Cantrecallmyusername
Board Regular
- Joined
- May 24, 2021
- Messages
- 50
- Office Version
- 365
- Platform
- Windows
Hi there,
I have data in column A where there are multiple varying lines of text within each cell. In column B and C I have one line of text.
Using a macro I want to split all the data in Column A into one line of text equal to one line of text and align the corresponding value in column B and C to the row.
Using the below code I can take the values in Column A and split them into rows however I cant seem to add the original values in column B and C to this
Sample of the data
I have data in column A where there are multiple varying lines of text within each cell. In column B and C I have one line of text.
Using a macro I want to split all the data in Column A into one line of text equal to one line of text and align the corresponding value in column B and C to the row.
Using the below code I can take the values in Column A and split them into rows however I cant seem to add the original values in column B and C to this
VBA Code:
Sub Format_text()
Dim cell_value As Variant
Dim counter As Integer
'Row counter
counter = 1
'Looping trough A column define max value
For i = 1 To 500
'Take cell at the time
cell_value = ThisWorkbook.ActiveSheet.Cells(i, 1).Value
'Split cell contents
Dim WrdArray() As String
WrdArray() = Split(cell_value, vbLf)
'Place values to the B column
For Each Item In WrdArray
ThisWorkbook.ActiveSheet.Cells(counter, 2).Value = Item
counter = counter + 1
Next Item
Next i
End Sub
Sample of the data
Cat Dog ZxxxxxxFxxxxxx xxxxxxRxxxxxxS xxxxxxOxxxxxx xxxxxxOxxxxxx 3 xxxxxx | Need this one | Need this one too |
Apple Fruit Berry Ice Cream Pear Orange | Include Me | Include Me too |