Last active
October 13, 2015 14:37
-
-
Save mattcan/4210384 to your computer and use it in GitHub Desktop.
Splits text in one column into two
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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