split values into multple cells based on criteria

kanth_sri_c

New Member
Joined
Apr 23, 2009
Messages
20
I've a cell with concatenated values separated by commas like this - [TABLE="width: 243"]
<TBODY>[TR]
[TD]10,20,AA,BB,30,40, CC, DD</SPAN>
[/TD]
[/TR]
</TBODY>[/TABLE]

I need them to split into 2 cells based on criteria
If 10,AA,CC show it in a new cell as -
[TABLE="width: 243"]
<TBODY>[TR]
[TD]10, AA,CC
And if the rest (20,BB,30,BB, DD) then in another cell.

Any help appreciated! thanks
</SPAN>
[/TD]
[/TR]
[TR]
[TD]</SPAN>
[/TD]
[/TR]
</TBODY>[/TABLE]
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Data in "A1" Results "B1" and "C1"
Code:
[COLOR="Navy"]Sub[/COLOR] MG09Aug23
[COLOR="Navy"]Dim[/COLOR] Txt
[COLOR="Navy"]Dim[/COLOR] n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Integer[/COLOR]
Txt = Split([a1], ",")
[COLOR="Navy"]For[/COLOR] n = 0 To UBound(Txt)
    [COLOR="Navy"]Select[/COLOR] [COLOR="Navy"]Case[/COLOR] Trim(Txt(n))
        [COLOR="Navy"]Case[/COLOR] "10", "AA", "CC": [b1] = [b1] & "," & Trim(Txt(n))
        [COLOR="Navy"]Case[/COLOR] Else: [C1] = [C1] & "," & Trim(Txt(n))
    [COLOR="Navy"]End[/COLOR] Select
[COLOR="Navy"]Next[/COLOR] n
[b1] = Mid([b1], 2)
[C1] = Mid([C1], 2)
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Mick, My list with concatenated values is growing. How i apply a for loop so that i can have the macro run for A2, A3 etc
just like the one above worked for A1 (10,20,AA,BB,30,40, CC, DD)
 
Upvote 0
Try this for Data in column "A".
Code:
[COLOR="Navy"]Sub[/COLOR] MG10Aug27
[COLOR="Navy"]Dim[/COLOR] Txt
[COLOR="Navy"]Dim[/COLOR] n           [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Integer[/COLOR]
[COLOR="Navy"]Dim[/COLOR] Rng         [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] Dn          [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("A2"), Range("A" & Rows.count).End(xlUp))
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
Txt = Split(Dn, ",")
[COLOR="Navy"]For[/COLOR] n = 0 To UBound(Txt)
    [COLOR="Navy"]Select[/COLOR] [COLOR="Navy"]Case[/COLOR] Trim(Txt(n))
        [COLOR="Navy"]Case[/COLOR] "10", "AA", "CC": Dn.Offset(, 1) = Dn.Offset(, 1) & "," & Trim(Txt(n))
        [COLOR="Navy"]Case[/COLOR] Else: Dn.Offset(, 2) = Dn.Offset(, 2) & "," & Trim(Txt(n))
    [COLOR="Navy"]End[/COLOR] Select
[COLOR="Navy"]Next[/COLOR] n
Dn.Offset(, 1) = Mid(Dn.Offset(, 1), 2)
Dn.Offset(, 2) = Mid(Dn.Offset(, 2), 2)
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

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