Splitting text string using formula...

Dan1000

Board Regular
Joined
Nov 4, 2006
Messages
210
I need to use a formula to split a text string using the commas as dividers with no spaces at either end of each string.

Maximum 4 commas to each string.

Is there a straight forward way of doing this rather than using the data to ccolumns excel command?

Regards
 
Hi Shrivallabha

Remark:
Application.Volatile makes the function inefficient and should only be used if absolutely necessary which is not the case.
Thank you PGC. I will keep that in mind.
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Here's another one...

A2 = some string

Entered in B2 and copied across until you get blanks:

=TRIM(MID(SUBSTITUTE(","&$A2&REPT(",",6),",",REPT(" ",255)),COLUMNS($B2:B2)*255,255))
Couldn't that bit be omitted?
 
Upvote 0

And I thought my generic formula was a bit on the long side :eeek:
 
Upvote 0
And I thought my generic formula was a bit on the long side
Aw, go on :oops:... I could have made it much longer if I had wanted to :biggrin:.

Just to make your formula completely "generic", this is what it would look like...

=TRIM(MID(SUBSTITUTE(A1,delimiter,REPT(" ",LEN(A1))),1+(fieldnumber*LEN(A1))-LEN(A1),LEN(A1)))

:warning: I plan to steal this formula for future postings of mine... but I will credit you when I do so. :wink:
 
Upvote 0
And I thought my generic formula was a bit on the long side
Aw, go on :oops:... I could have made it much longer if I had wanted to :biggrin:.

Just to make your formula completely "generic", this is what it would look like...

=TRIM(MID(SUBSTITUTE(A1,delimiter,REPT(" ",LEN(A1))),1+(fieldnumber*LEN(A1))-LEN(A1),LEN(A1)))

:warning: I plan to steal this formula for future postings of mine... but I will credit you when I do so. :wink:
Okay, now that I have had a full night's sleep (it was almost 5am when I saw/responded to your message) and had time to study our formulas, I see they were the same... once I removed the two beginning IF statements (meant to protect against empty cells or a fieldnumber of 1) and simply adjusted the field number calculation by 1 in order to handle what those two IF statements were doing. So, we both had the same underlying algorithm, you just saw the -1 adjustment that I missed.
 
Upvote 0

I was wondering if you would notice :biggrin: 5am is a good time to catch people off guard.
 
Upvote 0
I can not get either of the following two formaula to work and not sure why not. I have a text string in one cell I would like to divide using the commas by dragging out the formula...

=TRIM(MID(SUBSTITUTE(","&$A2&REPT(",",6),",",REPT(" ",255)),COLUMNS($B2:B2)*255,255))<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p> </o:p>
=TRIM(MID(SUBSTITUTE($A1,",",REPT(" ",LEN($A1))),1+(COLUMNS($B1:B1)*LEN($A1))-LEN($A1),LEN($A1)))


Any help please?
 
Upvote 0
I don't think the formulas in this are ddoing what I need.

I need to count the items before each comma and place them into separate - individual cells after the cell by dragging out.​
 
Upvote 0

Forum statistics

Threads
1,226,404
Messages
6,190,865
Members
453,619
Latest member
ahmedshehta

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