Skip to content

Instantly share code, notes, and snippets.

@mattcan
Last active October 13, 2015 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattcan/4210384 to your computer and use it in GitHub Desktop.
Save mattcan/4210384 to your computer and use it in GitHub Desktop.
Splits text in one column into two
Sub SplitColumn( _
ByVal LastRow As Long, _
ByVal DataCol As String, _
ByVal FirstPartCol As String, _
ByVal SecondPartCol As String, _
ByVal DelimCharacter As String _
)
Dim data_col As String, col_one As String, col_two As String, delimiter As String
data_col = DataCol
col_one = FirstPartCol
col_two = SecondPartCol ' you can safely make this the same as the data_col if you want to reuse
delimiter = DelimCharacter
Dim ws As Worksheet
Set ws = ActiveSheet
Dim i As Long, text_pieces As Variant
For i = 2 To lastrow
' split text on delim
text_pieces = Split(ws.Range(data_col & i).Value, delimiter)
' push text parts into columns
ws.Range(col_one & i).Value = text_pieces(0)
ws.Range(col_two & i).Value = text_pieces(1)
Next
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment