Break apart cell by commas

dcamos

Board Regular
Joined
May 21, 2008
Messages
225
I am trying to separate a cell into different cells based on the comma locations in the first cell. I am trying to do it with mid(find()) and just nesting more finds into the function but that is complicated. Is there an easier way to do this. This isn't a column but something i'd like to do automatically so i am trying to stay away from text to columns.

Thanks,
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
The cell could have in it red, blue, yellow, green, happy birthday
and I want to put red in one cell, blue in another, yellow in another, green, then ...
 
Upvote 0
Put this in a cell and drag right
=TRIM(MID(SUBSTITUTE(SUBSTITUTE(","&A1",,", ",", REPT(255," "),COLUMN(A999)), ",",REPT(255," "),COLUMN(B999)),255,255))
 
Upvote 0
Mike,
I a m getting an error in the Substitute(","&A1" I think i needed to put a & after the 1, but it still does not work.
 
Upvote 0
This should work,
=TRIM(MID(SUBSTITUTE(SUBSTITUTE(","&$A$1&",", ",", REPT(" ",255),COLUMN(B999)), ",", REPT(" ",255),COLUMN(A999)), 255, 255))
 
Upvote 0
Works perfectly, thank you. Could you please explain to me why it works, so I can learn.

Thanks,
 
Upvote 0
Can I ask for similar formula to break apart a cell by spaces?

So for example

A1
First Last

B1
First

C1
Last

Thanks
 
Upvote 0
First, put a comma in front of the string and after it ","&A1&","

In that string, replace the n+1'th comma with 255 spaces SUBSTITUTE(","&A1&",", ",", REPT(" ",255), n+1)

In that string, replace the n'th comma with 255 spaces SUBSTITUTE(SUBSTITUTE(...), ",", REPT(" ",255), n)

That gives us a short string, followed by 255 spaces, followed by the item of interest, followed by 255 spaces followed another short string.

MID(SUBSTITUTE(SUBSTITUTE(...)...), 255 , 255) will extract the item of interest with some surrounding spaces.

TRIM(MID(...)) removes those spaces.

The only thing left is to input the n+1 and n values in the SUBSTITUTE's. This is done with the COLUMN(B999) and COLUMN(A999), both of which increase as they are dragged right.
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,299
Members
452,904
Latest member
CodeMasterX

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