How to extract text between brackets but extracted text might have brackets as well

bee5s4

New Member
Joined
Oct 25, 2022
Messages
4
Office Version
  1. 365
Platform
  1. Windows
As the subject suggests, I'm trying to extract some text but seem to be spinning my wheels a little bit. I'm getting better at it but I'd definitely put myself in the novice category of Excel users.

The source text is in this format:
xxxx-xxxx (Some text here)
xxxx-xxxx (Some other text here(testing))


I want to extract the text between the outermost brackets and my current formula reads as follows:
=MID(L50,SEARCH("(",L50)+1,SEARCH(")",L50)-SEARCH("(",L50)-1)

This works for scenarios where the text has just the opening and closing bracket but when there's brackets embedded in the text, I get "some other text here(testing"

Is there a clean(er) way of doing this? Thank you in advance!
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Making progress.....my updated formula reads as follows:
=IF(RIGHT(L58,2)="))",MID(L58,SEARCH("(",L58)+1,SEARCH(")",L58)-SEARCH("(",L58)),MID(L58,SEARCH("(",L58)+1,SEARCH(")",L58)-SEARCH("(",L58)-1))

However, I could see this breaking if the text looked like:
xxxx-xxxx (Some text here (testing) but more text here)

I'd love to hear suggestions on how this might be accomplished as I'm still learning about available functions and trying to apply "good" logic within spreadsheets.
 
Upvote 0
See if the following formula works for you:
Excel Formula:
=MID(A1,FIND("(",A1)+1,FIND(CHAR(1),SUBSTITUTE(A1,")",CHAR(1),LEN(A1)-LEN(SUBSTITUTE(A1,")",""))))-FIND("(",A1)-1)
 
Upvote 0
Solution
You wizards!

Tetra201 - this did the trick so thank you for the quick help. I'll try to break the formula down to understand exactly what's happening and may circle back if I have questions.

Fluff - I'll try your suggestion later today and I like the simpler format. I assume textbefore/textafter are new(er) functions as I haven't encountered them in the past.
 
Upvote 0
Wound up not using it in this case as the end users don't utilize a recent version of Excel but I'll definitely be trying it out elsewhere. Seems like a simple solution to something that has long been a "clunky" formula.

Thank you both!
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,261
Messages
6,123,931
Members
449,134
Latest member
NickWBA

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