I am having trouble coding a macro to separate a cell with date and time information in to columns with TexttoColumns formula. This is the information I have in the column.
Beginning Date
1900-01-01 (00:00)
2008-09-25 (12:46)
I want all the column but the header to be split, with the date in one column and the hour in the next one.
In the macro I have, I am able to find the column I want to split and I create the new column to the right correctly. However, I am not able to do the text to column formula. this is the code I have:
Sub Separate_Date()
Cells.Find(What:="Fecha Inicio Proceso", After:=Cells(1, 1),
LookIn:=xlValues,
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False, SearchFormat:=False).Activate
Col = ActiveCell.Column
LastRow = ActiveCell.End(xlDown).Row
Cells(ActiveCell.Row, ActiveCell.Column + 1).EntireColumn.Insert
Columns(Col).Select
Range(Selection, Selection.End(xlDown)).Select
********Selection.TextToColumns Destination:=Range(Cells(2, Col),
Cells(LastRow, Col)),
DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
:=" ", FieldInfo:=Array(Array(1, 4), Array(2, 4)),
TrailingMinusNumbers:=True
End Sub
My code stops in the line marked with ****. It shows the error" Run time error. Destination reference is not valid".
I guess my problem is in the Range part, but I haven't been able to find any solution on the website.