Forum Discussion
How do I make text to columns automated?
Hi - thanks so much for replying. It would be option 2 but I would like the text to automatically split into the columns without doing it manually each time PascalKTeam
You may use VBA to automate this task.
Place the following code for Change Event on the Sheet Module and to do that, right click on the Sheet Tab --> View Code --> paste the code given below into the opened code window --> Close the VB editor and save your Workbook as Macro-Enabled Workbook.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cel As Range
On Error GoTo Skip
If Target.Column = 1 Then
Application.EnableEvents = False
For Each cel In Target.Cells
If cel <> "" Then
cel.TextToColumns comma:=True
End If
Next cel
End If
Skip:
Application.EnableEvents = True
End Sub
Please find the attached for reference. The Sheet1 Module has the above code.
To test the code, place a comma separated list (e.g. Word1,Word2,Word3,Word4) in any cell in Column A.
- amcruzApr 02, 2024Copper Contributor
Subodh_Tiwari_sktneer hi, can you also help to revised the VB command if the data need to separate using text to column is hyphen (-) not comma.. TIA

- JamesSpaldingMar 04, 2024Copper ContributorThis is the best thing ever. Thank you so much for posting this code. It is so easy to implement.