Separating data from a column to a new row

rach78

New Member
Joined
Oct 2, 2006
Messages
2
I've got a unique identifier in Column A, and Column B contains various text, which is locations. If there is more than one location, it is separated with a comma.

I'd like to have the data combined into only two columns. Where there is more than one location in Column B, a row would be inserted below the data, the unique identifier in Column A corresponding to that column would be copied down, and the location moved to the new row. This process would be repeated depending on the number of locations in the one cell in Column B.

Before example:
CR No Location
CR05/001 Box Hill, Ringwood
CR05/002 Box Hill
CR05/003 Ringwood, Lilydale, Croydon
CR05/004 Croydon
CR05/005 Ringwood

After example:
CR No Location
CR05/001 Box Hill
CR05/001 Ringwood
CR05/002 Box Hill
CR05/003 Ringwood
CR05/003 Lilydale
CR05/003 Croydon
CR05/004 Croydon
CR05/005 Ringwood

If anyone could tell me a quick way to do this it would be great!

Thanks
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

agihcam

Well-known Member
Joined
Jan 16, 2006
Messages
1,624
Welcome to the board.

try this code:
Code:
Sub test()
Dim a
Dim i, ii As Long
Range("c1").Resize(, 2) = Array("CR No", "Location")
For i = 2 To Range("b" & Rows.Count).End(xlUp).Row
    a = Split(Cells(i, "b").Value, ",")
     For Each m In a
        Range("d" & Rows.Count).End(xlUp).Offset(1) = m
        Range("d" & Rows.Count).End(xlUp).Offset(, -1) = Cells(i, "a").Value
     Next
Next
End Sub
 

Forum statistics

Threads
1,136,649
Messages
5,676,991
Members
419,667
Latest member
MegEri

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
Top