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.
 
In that case it appears that MS have got it wrong.
<section class="ocpArticleTitleSection"> [h=1]SUBSTITUTE function[/h] </section> <section class="supAppliesToSection" aria-label="This article" dir="ltr"> Excel for Office 365 Excel for Office 365 for Mac Excel for the web Excel 2019 Excel 2016 Excel 2019 for Mac Excel 2013 Excel 2010 Excel 2007 Excel 2016 for Mac Excel for Mac 2011 Excel Starter 2010 Less

</section>
https://support.office.com/en-gb/article/substitute-function-6434944e-a904-4336-a9b0-1e58df3bc332
 
Upvote 0

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Not exactly. If you look at the IF support page, we see the same list, not mentioning Excel 97, let alone Excel 2003, to wit:

Excel for Office 365 Excel for Office 365 for Mac Excel for the web Excel 2019 Excel 2016 Excel 2019 for Mac Excel 2013 Excel 2010 Excel 2007 Excel 2016 for Mac Excel for Mac 2011 Excel Starter 2010

Do you really believe that means the IF function was introduced in Excel 2007?!

My guess: That list identifies only versions of Excel that MSFT "supports". I'm not sure that still includes Excel 2007. But it definitely does not include Excel 2003 and before.

Moreover, MSFT support pages should not be trusted to be accurate. Anything that seems "surprising" should be tested. That goes double for the sanitized support pages that we find online these days, which omit critical information and sometimes simply misstates it.
 
Last edited:
Upvote 0
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.
Some comments ..

1. You have an errant parenthesis in your formula

2. If you are a stickler for including assumptions, then you would need to either
a) Include assumptions your formula contains about the overall length of the original string & sub-strings (refer to cells B11:B14 below which are supposed to be extracting the 11th to 14th strings from the column A string), or
b) Make your formula more general by addressing the caution Rick raises towards the end of his article and as covered in posts 3 & 5 of that thread.

I have used that further generalisation, together with your 'space' resolution, in column C

Excel Workbook
ABC
1aString 1aString 1aString 1
2aString 1/aString 2aString 2aString 2
3aString 1/aString 2/aString 3aString 3aString 3
4aString 1/aString 2/aString 3/aString 4aString 4aString 4
5aString 1/aString 2/aString 3/aString 4/aString 5aString 5aString 5
6aString 1/aString 2/aString 3/aString 4/aString 5/aString 6aString 6aString 6
7aString 1/aString 2/aString 3/aString 4/aString 5/aString 6/aString 7aString 7aString 7
8aString 1/aString 2/aString 3/aString 4/aString 5/aString 6/aString 7/aString 8aString 8aString 8
9aString 1/aString 2/aString 3/aString 4/aString 5/aString 6/aString 7/aString 8/aString 9aString 9aString 9
10aString 1/aString 2/aString 3/aString 4/aString 5/aString 6/aString 7/aString 8/aString 9/aString 10aString 10aString 10
11aString 1/aString 2/aString 3/aString 4/aString 5/aString 6/aString 7/aString 8/aString 9/aString 10/aString 11aStringaString 11
12aString 1/aString 2/aString 3/aString 4/aString 5/aString 6/aString 7/aString 8/aString 9/aString 10/aString 11/aString 1211aString 12
13aString 1/aString 2/aString 3/aString 4/aString 5/aString 6/aString 7/aString 8/aString 9/aString 10/aString 11/aString 12/aString 13aString 12aString 13
14aString 1/aString 2/aString 3/aString 4/aString 5/aString 6/aString 7/aString 8/aString 9/aString 10/aString 11/aString 12/aString 13/aString 14aString 13aString 14
Extract String




My guess: That list identifies only versions of Excel that MSFT "supports".
That is my understanding.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,223
Members
452,620
Latest member
dsubash

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