Excel formula (not VBA) to extract delimited string?

joeu2004

Banned user
Joined
Mar 2, 2014
Messages
3,080
Office Version
  1. 2010
Platform
  1. Windows
I have the abstract string "firstString/secondString/thirdString/fourthString" in C2.

I want to use a single Excel formula (not VBA; no helper cells) to extract "secondString". Any ideas?

Note that "*String" is any arbitrary sequence of characters, not including "/". So, the formula must depend on only the delimiters ("/"), not the length of substrings or the characters themselves in between.

Also, the solution must be limited to Excel 2003 functions.

Off-hand, the best I can do is:

=REPLACE(LEFT(C2, FIND("/",C2, FIND("/",C2)+1)-1), 1, FIND("/", C2), "")

Can we do better?


-----
I'm helping someone in another forum. The above meets his needs. But for "extra credit", the ideal formula can be easily adapted to extract "thirdString". Sigh, my formula would be cumbersome to adapt for that purpose.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Slightly shorter
=MID(C2,FIND("/",C2)+1,FIND("/",C2,FIND("/",C2)+1)-FIND("/",C2)-1)
 
Upvote 0
I'm helping someone in another forum. The above meets his needs. But for "extra credit", the ideal formula can be easily adapted to extract "thirdString".
Probably covered by Rick in FormR's link but I didn't look.
This adaptation of Dante's formula easily allows that by changing the red number

=TRIM(MID(SUBSTITUTE(C2,"/",REPT(" ",255)),255*2-254,255))
 
Last edited:
Upvote 0
Thanks FormR and Peter. Rick's article is definitely a keeper. Just an observation.... I'm a big fan of explaining assumptions, for the benefit of the unsuspecting user. The TRIM/REPT paradigm presumes that the delimited substrings ("fields") do not contain spaces that need to be retained. A valid assumption in my immediate case. But more generally, I would write:

=SUBSTITUTE(MID(SUBSTITUTE(A1, delimiter, REPT(unusedChar,99)), fieldNumber*99-98, 99)), unusedChar, "")

where "unusedChar" can be CHAR(1), if necessary.
 
Upvote 0
I would also point out (for anyone that doesn't know) the substitute function first appeared in xl2007, so does not fit your criteria of working in xl2003.
 
Upvote 0
the substitute function first appeared in xl2007, so does not fit your criteria of working in xl2003

That is incorrect!

First, when we save as "xls" in Excel 2010, the compatibility checker does not flag the use of SUBSTITUTE. In contrast, it does flag the use of COUNTIFS.

Second, I still have Excel 2003 on my WinXP computer, and I can use the SUBSTITUTE function therein. The screen tips shows the same usage of SUBSTITUTE in Excel 2003 as it does in Excel 2010.

Finally, when I use Excel 2003 to open the "xls" file that I saved with Excel 2010, the COUNTIFS function appears as _xlfn.COUNTIFS (unsupported function), whereas SUBSTITUTE appears as-is (supported function).

QED.
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,141
Members
453,021
Latest member
Justyna P

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