Hello All,
I'm trying to create a macro which splits data out of textjoin formula and output it as list.
I have created a macro which do that, but it's not moving the cells and the data is not correct. So I need to adjust the macro to add empty cell in column G to keep up with the data.
Here is my macro at the moment:
Sub SeparateDataForEachCell()
Dim lastRow As Long
Dim dataRange As Range
Dim cell As Range
Dim dataString As String
Dim dataArray() As String
Dim outputRange As Range
Dim outputCell As Range
Dim i As Integer
lastRow = Cells(Rows.Count, "I").End(xlUp).Row
Set dataRange = Range("I1:I" & lastRow)
For Each cell In dataRange
dataString = cell.Value
dataArray = Split(dataString, " / ")
Set outputCell = cell.Offset(0, -1)
For i = LBound(dataArray) To UBound(dataArray)
outputCell.Value = dataArray(i)
Set outputCell = outputCell.Offset(1)
Next i
Next cell
End Sub
Here is an example table:
I'm trying to create a macro which splits data out of textjoin formula and output it as list.
I have created a macro which do that, but it's not moving the cells and the data is not correct. So I need to adjust the macro to add empty cell in column G to keep up with the data.
Here is my macro at the moment:
Sub SeparateDataForEachCell()
Dim lastRow As Long
Dim dataRange As Range
Dim cell As Range
Dim dataString As String
Dim dataArray() As String
Dim outputRange As Range
Dim outputCell As Range
Dim i As Integer
lastRow = Cells(Rows.Count, "I").End(xlUp).Row
Set dataRange = Range("I1:I" & lastRow)
For Each cell In dataRange
dataString = cell.Value
dataArray = Split(dataString, " / ")
Set outputCell = cell.Offset(0, -1)
For i = LBound(dataArray) To UBound(dataArray)
outputCell.Value = dataArray(i)
Set outputCell = outputCell.Offset(1)
Next i
Next cell
End Sub
Here is an example table:
Book1 | |||||
---|---|---|---|---|---|
G | H | I | |||
1 | Test | ABC | ABC | ||
2 | Test23 | ABC | ABC / ABV / AB23 | ||
3 | Test24 | ABB | ABB / AVV / AWW | ||
4 | Test25 | ACC | ACC / ATT / AWQ / AUU | ||
5 | ATT | ||||
6 | AWQ | ||||
7 | AUU | ||||
8 | Up you can see the output which I'm getting now | ||||
9 | Below is the ouput which I'm looking for | ||||
10 | Test | ABC | |||
11 | Test23 | ABC | |||
12 | ABV | ||||
13 | AB23 | ||||
14 | Test24 | ABB | |||
15 | AVV | ||||
16 | AWW | ||||
17 | Test25 | ACC | |||
18 | ATT | ||||
19 | AWQ | ||||
20 | AUU | ||||
Sheet1 |