0

I have a table that has six columns. I would like the integer values in one single cell (F2) to be separated into multiple rows.

Additionally, I need the rows from A-E to be associated with integer.

I found a post akin to what I need, but it only works if you have two columns.

enter image description here

The code I have been trying to run

Sub ChickatAH()
    Dim rng As Range, Lstrw As Long, c As Range
    Dim SpltRng As Range
    Dim i As Integer
    Dim Orig As Variant
    Dim txt As String

    Lstrw = Cells(Rows.Count, "F").End(xlUp).Row
    Set rng = Range("A2:F" & Lstrw)

    For Each cell In rng.Cells
        Set SpltRng = cell.Offset(, 1)
        txt = SpltRng.Value
        Orig = Split(txt, Chr(10))
    For i = 0 To UBound(Orig)
        Cells(Rows.Count, "H").End(xlUp).Offset(1) = cell
        Cells(Rows.Count, "H").End(xlUp).Offset(, 1) = Orig(i)
    Next i
Next cell
End Sub
Community
  • 1
  • 1
user716255
  • 201
  • 3
  • 13

1 Answers1

0

Modified the code on this post. It generated the solution I wanted. VBA: Split cell values into multiple rows and keep other data

Sub splitByColF()
    Dim r As Range, i As Long, ar
    Set r = Worksheets("Sheet1").Range("F999999").End(xlUp)
    Do While r.Row > 1
        ar = Split(r.Value, Chr(10))
        If UBound(ar) >= 0 Then r.Value = ar(0)
        For i = UBound(ar) To 1 Step -1
            r.EntireRow.Copy
            r.Offset(1).EntireRow.Insert
            r.Offset(1).Value = ar(i)
        Next
        Set r = r.Offset(-1)
    Loop
End Sub
user716255
  • 201
  • 3
  • 13