Turn multiple lines in one cell into multiple rows

Joe B

New Member
Joined
Jun 15, 2007
Messages
22
I'm sorry if there is a thread like this, but I have looked at a lot of thread and none of them have worked for me.

I have two columns. the first column has names and the second column has information separated by a line break (Alt + Enter).

It would look something like this:

A1= Joe B1= "asdf
fdfsf
fsfsfgds"
A2= Sally B2= "fref
grewgwe
grr"

My goal is to turn this information into a table with each line being a separate cell.

Joe asdf
Joe fdfsf
Joe fsfsfgds
Sally fref
Sally grewgwe
Sally grr

Can anyone help me on this? Thanks!
 
Last edited:

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
try
Code:
Sub n()
    Dim shSource As Worksheet
    Dim shDestin As Worksheet
    Dim c As Variant, i As Integer
    Dim LR As Long, r As Long, L As Long
    Set shSource = Sheets("Sheet1")
    Set shDestin = Sheets("Sheet2")
    LR = shSource.Cells(Rows.Count, "A").End(xlUp).Row
    For r = 1 To LR
        c = Split(Range("B" & r), Chr(10))
        For i = 0 To UBound(c)
            L = L + 1
            shDestin.Cells(L, 1) = shSource.Range("A" & r)
            shDestin.Cells(L, 2) = c(i)
        Next i
    Next r
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,095
Messages
6,128,790
Members
449,468
Latest member
AGreen17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top