Hi,
looking for some help with vba to split a text string. The code I have is as follows:
The code works fine but I've updated from when it was first written for me and here is my issue. I want to use it to split a string based a 'time' within the string ie cell B3 contains "abc de12:30 fg hij" and I would like to split it so cell F3 contains "abc de", "fg hij" in cell G3 and 'time' part of the string "12:30" in cell H3
The pattern of the text in the string can vary in number of words of characters so needs to be split based on the 'time'
Thanks,
EMcK
looking for some help with vba to split a text string. The code I have is as follows:
Code:
Sub SplitText()
Dim numRows As Long
Dim arrText As Variant
Dim rw As Long
With Sheets("Sheet1")
'get the number of rows
numRows = .Cells(.Rows.Count, "B").End(xlUp).Row
For rw = 3 To numRows
'test for ":" is in string, if so, split into array and process
If InStr(.Range("B" & rw).Value, ":") Then
arrText = split(.Range("B" & rw).Value, ":") 'split string on :
'output
.Range("F" & rw).Value = arrText(0)
.Range("H" & rw).Value = arrText(1)
End If
Next rw
End With
End Sub
The code works fine but I've updated from when it was first written for me and here is my issue. I want to use it to split a string based a 'time' within the string ie cell B3 contains "abc de12:30 fg hij" and I would like to split it so cell F3 contains "abc de", "fg hij" in cell G3 and 'time' part of the string "12:30" in cell H3
The pattern of the text in the string can vary in number of words of characters so needs to be split based on the 'time'
Thanks,
EMcK
Last edited: