• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Splitting cells according to no: of text separate by Atl+enter (Char(10))

I have this file where in column A the data are clubbed w.r.t to other columns.
I need to split the value in a Column A on each cell rows into multiple rows by inserting rows and copy the remaining column data B onwards.
I have started with this code below but now I am lost. Can you please help me to complete. The file is attached
Sub splitText()

Dim splitVals As Variant
Dim totalVals As Long
Dim FRow As Long
Dim LRow As Long
Dim R As Long
Dim Col As Variant

Col = "A"
FRow = 2
LRow = Cells(Rows.Count, "A").End(xlUp).Row
With ActiveSheet
For R = LRow To FRow + 1 Step -1
splitVals = Split(Cells(LRow, Col).Value, Chr(10))
totalVals = UBound(splitVals) + 1
Cells(R, Col).EntireRow.Resize(totalVals).Insert
??
 

Attachments

  • sample - split into rows.xlsx
    10.1 KB · Views: 6
Code:
Sub Demo()
    With Sheet1.Cells(1).CurrentRegion.Rows
        For R& = .Count To 2 Step -1
                      SP = Split(.Cells(R, 1).Value, vbLf)
            If UBound(SP) Then
                .Item(R).Offset(1).Resize(UBound(SP)).Insert xlDown
                .Item(R).Copy .Item(R).Offset(1).Resize(UBound(SP))
                .Cells(R, 1).Resize(UBound(SP) + 1).Value = Application.Transpose(SP)
            End If
        Next
    End With
End Sub
Do you like it ? So thanks to click on bottom right Like !​
 
Last edited:
Code:
Sub myClick()
    Dim arr, brr, intLoop, intAcc
    Dim arrTemp, intRow
    arr = ActiveSheet.[a1].CurrentRegion
    ReDim brr(1 To 10000, 1 To 3)
    For intLoop = 1 To UBound(arr)
        arrTemp = Split(arr(intLoop, 1), vbLf)
        For intRow = 0 To UBound(arrTemp)
            If arrTemp(intRow) <> "" Then
                intAcc = intAcc + 1
                brr(intAcc, 1) = arrTemp(intRow)
                brr(intAcc, 2) = arr(intLoop, 2)
                brr(intAcc, 3) = arr(intLoop, 3)
            End If
        Next
    Next
    ActiveSheet.[f1].Resize(intAcc, 3) = brr
End Sub
 
Thanks MARC, very much appreciated. Excellent work
But since I am new to VB, what was wrong in my approach and if you could explain your method line by line.
Thanks once again
 
Back
Top