How to break up one long line of names into rows

rickyckc

Active Member
Joined
Apr 1, 2004
Messages
327
Hi all,

Suppose I have in A1, names of people seperated by comma....

James Dean, Bruce Lee, Marilyn Monroe, Tom Cruise, etc

How do I break them into rows like

James Dean
Bruce Lee
Marilyn Monroe
Tom Cruise

Thanks.

Best Regards,
Ricky
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
First use Data>Text To Columns and pick comma as the delimiter.

Then copy the names and PasteSpecial>Transpose to convert from columns to rows.
 
Upvote 0
Hi Lewiy,

What if I have more than 256 names, say example 400 names, will it wrap over to second row ?

Thanks.

Best Regards,
Ricky
 
Upvote 0
try
Code:
Sub test()
Dim x
x = Split(Range("a1").Value, ",")
Range("b1").Resize(UBound(x)+1).Value = Application.Transpose(x)
End Sub
 
Upvote 0
Unfortunately, it will not wrap and you will lose the excess data. However, you could always split the data manually into 2 rows quite easily beforehand.
 
Upvote 0
Hi jindon,

Thanks, yur script works. I believe it works even if i have 5000 names ?

Best Regards,
Ricky
 
Upvote 0
Hi jindon,

I have tested more than 1,000 names and it works. Thanks again !

Best Regards,
Ricky
 
Upvote 0
Ricky

If you have more than 5000 (didn't remember exactly 5050?), tranpose function my not return correct value.
In that case
Code:
Sub test()
Dim x, i As Long, a(), i As Long
x = Split(Range("a1").Value, ",")
If UBound(x) > 5000 Then
     ReDim a(1 To UBound(x) +1, 1 To 1)
     For i = 0 To UBound(x)
          a(i + 1,1) = x(i)
     Next
     Range("b1").Resize(UBound(a,1)).Value = a
Else
     Range("b1").Resize(UBound(x)+1).Value = Application.Transpose(x)
End If
End Sub
 
Upvote 0
Hi jindon,

Was there a typo on the first line ? I changed it to

Code:
Sub test(), a(), i As Long 
Dim x, i As Long 
x = Split(Range("a1").Value, ",") 
If UBound(x) > 5000 Then 
     ReDim a(1 To UBound(x) +1, 1 To 1) 
     For i = 0 To UBound(x) 
          a(i + 1,1) = x(i) 
     Next 
     Range("b1").Resize(UBound(a,1)).Value = a 
Else 
     Range("b1").Resize(UBound(x)+1).Value = x 
End If 
End Sub


and tested it on 4 names. What happens is it repeats the first name only, 5 times.

Thanks.

Best Regards,
Ricky
 
Upvote 0
...sorry, i mean i changed it to this...

Code:
Sub test()
Dim x, a(), i As Long
x = Split(Range("a1").Value, ",")
If UBound(x) > 5000 Then
     ReDim a(1 To UBound(x) + 1, 1 To 1)
     For i = 0 To UBound(x)
          a(i + 1, 1) = x(i)
     Next
     Range("b1").Resize(UBound(a, 1)).Value = a
Else
     Range("b1").Resize(UBound(x) + 1).Value = x
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,618
Messages
6,120,544
Members
448,970
Latest member
kennimack

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