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 is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
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
 
Upvote 0

Forum statistics

Threads
1,214,772
Messages
6,121,459
Members
449,033
Latest member
Kcolwell16

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