Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 90280

How to split a single cell into multiple rows?

$
0
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

Viewing all articles
Browse latest Browse all 90280

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>