How to Split string in VBA
You can split a string into two substrings. Suppose you have a string in “A” columns then by using the below code you can convert into two substrings in columns “B” and columns “C”. String splits where it finds space.
Sub SplitText()
Sheets("Sheet1").Select
Range("C1").Select
Do Until Selection.Value = ""
Dim avarSplit As Variant
avarSplit = Split(Selection.Value, " ")
Selection.Offset(0, 1).Value = avarSplit(0)
Selection.Offset(0, 2).Value = avarSplit(1)
Selection.Offset(1, 0).Select
Loop
Range("A1").Select
End Sub
Sub SplitText()
Sheets("Sheet1").Select
Range("C1").Select
Do Until Selection.Value = ""
Dim avarSplit As Variant
avarSplit = Split(Selection.Value, " ")
Selection.Offset(0, 1).Value = avarSplit(0)
Selection.Offset(0, 2).Value = avarSplit(1)
Selection.Offset(1, 0).Select
Loop
Range("A1").Select
End Sub
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.