Hi,
I've got a silly error here and can't think how to fix it. I have the following code that splits a text string for me based on the first space and offsets the string into the adjacent columns, that's all fine. However rather than looping through each cell in my range, it offsets the same string into all cells in the range then repeats this until it gets to the last cell in the range. So rather than having all the cells in my range split I essentially only have one cell split. As I said I'm sure its a silly error but can't think what I need to do to fix this.
I'm just wanting to keep the code as quick and simple that splits the range of cells that I manually highlight.
Thanks,
EMcK
I've got a silly error here and can't think how to fix it. I have the following code that splits a text string for me based on the first space and offsets the string into the adjacent columns, that's all fine. However rather than looping through each cell in my range, it offsets the same string into all cells in the range then repeats this until it gets to the last cell in the range. So rather than having all the cells in my range split I essentially only have one cell split. As I said I'm sure its a silly error but can't think what I need to do to fix this.
Code:
Sub SplitText()
Dim pos As Long
Dim r As Range, c As Range
Set r = Selection
For Each c In r
pos = InStr(c, " ")
If pos Then
r.Offset(, 1) = Trim(Left(c, pos - 1))
r.Offset(, 2) = Trim(Mid(c, pos + 3))
End If
Next c
End Sub
I'm just wanting to keep the code as quick and simple that splits the range of cells that I manually highlight.
Thanks,
EMcK