Está en la página 1de 1

Excel Date Sort Macro

Sub DtSrt()
Dim StRw As Integer, EndRw As Integer
StRw = 7 ' Starting Row
EndRw = Range("E65500").End(xlUp).Row
Rows(StRw & ":" & EndRw).Select
Selection.Sort Key1:=Range("E7"), Order1:=xlAscending
End Sub

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------
Convert Text to Date

If you want to use a VBA macro, the following assumes

Your data starts in A1 and is in column A


The results will go in Column B -- but you can easily change the code to overwrite,
once you see it is working ok
The format is similar to your examples: Date and Time are separated by a single
space; Date components are separated by < dot >; time components are separated by <
colon >
Option Explicit
Sub ConvertDateTimeString()
Dim vraw, vRes()
Dim vDT, vTime, V
Dim DT As Date, TM As Date
Dim I As Long, S As String

vraw = Range("a1", Cells(Rows.Count, "A").End(xlUp))


If VarType(vraw) < vbArray Then 'check for only one entry
ReDim vraw(1 To 1, 1 To 1)
vraw(1, 1) = [a1]
End If
ReDim vRes(1 To UBound(vraw), 1 To 1)

For I = 1 To UBound(vraw)
S = vraw(I, 1)
vDT = Split(Split(S)(0), ".")
vTime = Split(Split(S)(1), ":")

DT = DateSerial(vDT(2), vDT(1), vDT(0))


vTime = TimeSerial(vTime(0), vTime(1), vTime(2))
vRes(I, 1) = DT + vTime
Next I

With Range("B1").Resize(UBound(vRes), 1)
.EntireColumn.Clear
.Value = vRes
.NumberFormat = "dd.mm.yyyy hh:mm:ss"
.EntireColumn.AutoFit
End With
End Sub

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------

También podría gustarte