Hi
Could you please help me with the following code to split the date and time from selection to two separate adjutant columns?
The code is working fine but I know that there a room for improvement instead of duplicating the same code. But I'm not much sure of it using the arrays.
Thanks, in advance.
Sub DateTime()
Dim myVals As Variant, y As Variant
Dim i As Long
myVals = Selection.Value2
On Error Resume Next
For i = 1 To UBound(myVals)
y = Split(myVals(i, 1))
myVals(i, 1) = Format(y(0), "dd/mmm/yyyy")
Next i
ActiveCell.EntireColumn.Offset(0, 1).Insert
Selection.Offset(, 1).Value = myVals
Erase myVals
myVals = Selection.Value2
On Error Resume Next
For i = 1 To UBound(myVals)
y = Split(myVals(i, 1))
myVals(i, 1) = Format(y(1), "hh:mm AM/PM")
Next i
ActiveCell.EntireColumn.Offset(0, 2).Insert
Selection.Offset(, 2).Value = myVals
End Sub