I have many columns of concatenated data that I would like to split by spaces.
So from this:
To this:
This VBA code is very close,
Sub TextToColumns()
'Deines Last Row
Dim LastRow As Long
LastRow = 1048576 'the last row possible in excel
'optional alternative **LastRow** Code
'Counts number of rows (counts from last row of Column A):
'Dim LastRow As Long
'LastRow = Cells(Rows.Count, "A").End(xlUp).Row
'Counts number of Columns (my headers start in row 1)
Dim LastColumn As Long
LastColumn = Cells(1, Columns.Count).End(xlToLeft).Column
'Loops Text to columns
Dim StartingRow, StartingColumn As Long
StartingRow = 1
For StartingColumn = 1 To LastColumn
Range(Cells(StartingRow, StartingColumn), Cells(LastRow, StartingColumn)).Select
Selection.TextToColumns , DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=True, Other:=False, FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True
Next
End Sub
but I would like to use it only on the selected cells, and it overwrites the data to give this:
How can I avoid overwriting the data, and only run the macro on selected cells? Thank you very much.