I am really new to VBA coding.
Problem I have is this:
B60, D60, F60, H60 (etc) cells have different values in this format: x, y, z
(x, y and z can be numbers 0-10)
I’d like to splice this so it becomes:
B60 = x
B61 = y
B62 = z
D60 = x2
D61 = y2
D62 = z2
etc.
I’ve found this code:
Dim objRegex
Dim Z
Dim Y
Dim lngRow As Long
Dim lngCnt As Long
Dim tempArr() As String
Dim strArr
Set objRegex = CreateObject("vbscript.regexp")
objRegex.Pattern = "^\s+(.+?)$"
'Define the range to be analysed
Z = Range([a1], Cells(Rows.Count, "b").End(xlUp)).Value2
ReDim Y(1 To 2, 1 To 1000)
For lngRow = 1 To UBound(Z, 1)
'Split each string by ","
tempArr = Split(Z(lngRow, 2), ",")
For Each strArr In tempArr
lngCnt = lngCnt + 1
'Add another 1000 records to resorted array every 1000 records
If lngCnt Mod 1000 = 0 Then ReDim Preserve Y(1 To 2, 1 To lngCnt + 1000)
Y(1, lngCnt) = Z(lngRow, 1)
Y(2, lngCnt) = objRegex.Replace(strArr, "$1")
Next
Next lngRow
'Dump the re-ordered range to columns C:D
[a1].Resize(lngCnt, 2).Value2 = Application.Transpose(Y)
But this doesn’t quite work for me. I only need row 60 to do this. I really tried editing this code, but I don’t understand any of it… Can someone help me out please? It’s really appreciated.
This will do the trick for you. Works only on row 60, and will not overwrite the existing values, so you can check for accuracy. Will only work for 3 comma-separated values in each cell.
If you have a varying number of comma-separated values in each cell, you will need to change the line:
to
EDIT
Fixed code to work with 1 blank column between each column of data.