How can I separate date and time in the following excel?
The user should be able to insert the two columns "Date&Time" and "Power" any where in any worksheet and the button should separate date and time in 2 columns and copy power next to them in the same worksheet where data is.
That is where the user specifies the first cell of his data, which is been asked in you UF.
When de button is in another sheet, you need a sheetreference too.
According to your attachment an Excel basics VBA demonstration (v2) as a beginner starter
to paste only in the Tabelle1 worksheet module :
PHP Code:
Sub Demo1() Dim Rc As Range Set Rc = UsedRange.Find("Time stamp", , , 1, 1): If Rc Is Nothing Then Beep: Exit Sub Application.DisplayAlerts = False With Range(Rc, Rc.End(xlDown)).Resize(, 2).Columns .Item(2).Insert .Item(1).TextToColumns , 1, xlTextQualifierNone, , False, False, False, True, False End With Application.DisplayAlerts = True Rc(2).Resize(, 2) = Split(Rc(2), "-") Set Rc = Nothing End Sub
► Do you like it ? ► ► So thanks to click on bottom left star icon ? ★ Add Reputation ? ! ◄ ◄
Last edited by Marc L; 09-17-2022 at 09:55 AM.
Reason: optimization ...
According to your attachment an Excel basics VBA demonstration (v2) as a beginner starter
to paste only in the Tabelle1 worksheet module :
PHP Code:
Sub Demo1() Dim Rc As Range Set Rc = UsedRange.Find("Time stamp", , , 1, 1): If Rc Is Nothing Then Beep: Exit Sub Application.DisplayAlerts = False With Range(Rc, Rc.End(xlDown)).Resize(, 2).Columns .Item(2).Insert .Item(1).TextToColumns , 1, xlTextQualifierNone, , False, False, False, True, False End With Application.DisplayAlerts = True Rc(2).Resize(, 2) = Split(Rc(2), "-") Set Rc = Nothing End Sub
► Do you like it ? ► ► So thanks to click on bottom left star icon ? ★ Add Reputation ? ! ◄ ◄
According to your attachment an Excel basics VBA demonstration (v2) as a beginner starter
to paste only in the Tabelle1 worksheet module :
PHP Code:
Sub Demo1() Dim Rc As Range Set Rc = UsedRange.Find("Time stamp", , , 1, 1): If Rc Is Nothing Then Beep: Exit Sub Application.DisplayAlerts = False With Range(Rc, Rc.End(xlDown)).Resize(, 2).Columns .Item(2).Insert .Item(1).TextToColumns , 1, xlTextQualifierNone, , False, False, False, True, False End With Application.DisplayAlerts = True Rc(2).Resize(, 2) = Split(Rc(2), "-") Set Rc = Nothing End Sub
► Do you like it ? ► ► So thanks to click on bottom left star icon ? ★ Add Reputation ? ! ◄ ◄
For Range.Find(), there are nine parameters:
What ,After, LookIn, LookAt, SearchOrder, SearchDirection, MatchCase, MatchByte & SearchFormat
So:
-What = "Time stamp"
-After: (where to start), is not specified so it defaults to upper left cell of the range
-LookIn: can have one of four options: 1) xlFormulas, 2) xlValues, 3) xlComments, 4) xlCommentsThreaded. It wasn't specified in the macro so it defauts to #1
-LookAt: has two options: 1) xlWhole & 2) xlPart. The macro specifies option #1
-SearchOrder: has two options: 1) xlByRows & 2) xlByColumns. Option #1 is specified.
The rest of the paraments use the defaults. It could be written:
Set Rc = UsedRange.Find(What:="Time stamp", LookAt:=xlWhole, SearchOrder:=xlByRows)
I know it findes the "time stamp" column but what is this ", , , 1, 1" part?
'Cause here I just follow the Range.Find VBA help, all is there, a must read !
You can have the extended syntax like in post #12 just using the Macro Recorder ...
Bookmarks