Separate Cell Values with Comma and transfer into Column

ivandgreat

Board Regular
Joined
Jun 20, 2012
Messages
95
Hi,

I wanted to separate my cell values with comma into a column

ItemDepIDsNoIDA
1200012000
22000, 200122001
32001, 2000, 200232002

<tbody>
</tbody>

the output will be below table,

ItemIDADepIDs
120002000
220012000
320012001
420022000
520022001
620022002

<tbody>
</tbody>

br,
ivan
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Suppose table starting in A1
Code:
Sub a()
LR = Cells(Rows.Count, "A").End(xlUp).Row
dcol = 6
drow = 2
n = 1
Range("F1") = Range("A1")
Range("G1") = Range("D1")
Range("H1") = Range("B1")
For j = 2 To LR
  If InStr(Cells(j, 2), ",") = 0 Then
    Range("F" & drow) = n
    Range("G" & drow) = Range("D" & j)
    Range("H" & drow) = Range("B" & j)
    drow = drow + 1
    n = n + 1
  Else
    ar = Split(Cells(j, 2), ",")
    For i = 0 To UBound(ar)
      Range("F" & drow) = n
      Range("G" & drow) = Range("D" & j)
      Range("H" & drow) = ar(i)
      drow = drow + 1
      n = n + 1
    Next
  End If
Next
End Sub
 
Upvote 0
Thanks patel45, I have tried it and works fine. Any idea how to make it more faster, I'm having more than 1000 rows with 10 to 50 values to work on.

Thanks a lot.
 
Upvote 0

Forum statistics

Threads
1,214,594
Messages
6,120,436
Members
448,964
Latest member
Danni317

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