TEXTBEFORE/MID/FIND Formula Help

rachel06

Board Regular
Joined
Feb 3, 2016
Messages
155
Office Version
  1. 365
Platform
  1. Windows
Hi!

I use this formula to find a string of "0196". Wondering if there is a way to add more strings for it to find? Like if it finds 0196 or 0249 to perform the formula?

=TEXTBEFORE(MID(A2,FIND("0196",A2),255),{" ","."})

I've tried adding it in the {} like the delimiters are, but then it's using two columns instead of just one. - IE I have the formula in cell C3, and it's searching for 0196 there and 0249 in D3. I hope this makes sense!

In case you need some dummy data....
Company ABC 0196-9999 Rate Sheet 01-01-2025
Company XYZ 0249-9999 Rate Sheet 01-01-2025

I'd like the formula to pull out 0196-9999 or 0249-9999 with these, in the cell the formula is in. The formula above works for the 0196, but I cannot figure out how to incorporate the 0249. There may be more I need to add later I'm sure when I get a working formula for this, it'll be easy to add more as needed.

Any help is greatly appreciated!
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Try:
Tips2025.xlsx
AB
1
2Company ABC 0196-9999 Rate Sheet 01-01-20250196-9999
3Company XYZ 0249-9999 Rate Sheet 01-01-20250249-9999
Sheet1
Cell Formulas
RangeFormula
B2:B3B2=LET(t,TEXTSPLIT(A2," "),FILTER(t,MAP(t,LAMBDA(m,OR(ISNUMBER(FIND({"0196","0249"},m)))))))
 
Upvote 0
Solution
I think this single formula will do what you want (change the two occurrences of the range to match your actual data)...
Excel Formula:
=IFERROR(MID(A2:A9,BYROW(IFERROR(FIND({"0196","0249"},A2:A9),""),CONCAT),9),"")
 
Last edited:
Upvote 0
I wish I could mark you both as solutions. Thanks so much! I didn't think it'd be that complex of a formula!
 
Upvote 0
TextBefore.xlsm
ACD
1
2Company ABC 0196-9999 Rate Sheet 01-01-20250196-99990196-9999
3Company XYZ 0249-9999 Rate Sheet 01-01-20250249-99990249-9999
4Company XYZ 2249-9999 Rate Sheet 01-01-2025  
4a
Cell Formulas
RangeFormula
C2:C4C2=IF(COUNT(FIND({"0196","0249"},A2)),TEXTAFTER(TEXTBEFORE(A2," ",3)," ",2),"")
D2:D4D2=IF(COUNT(FIND({"0196","0249"},A2)),LEFT(TEXTAFTER(A2," ",2),9),"")
 
Upvote 0
Here's another solution that is a bit more efficient and robust (not relying on the position of the delimiters or fixed length of the code string).
Tips2025.xlsx
ABC
1Single cellArray
2Company ABC Test 0196-9999 Rate Sheet 01-01-20250196-99990196-9999
3Company 0249-9999 Rate Sheet 01-01-20250249-99990249-9999
4Company XYZ 2249-9999 Rate Sheet 01-01-2025 
5Company ABC XYZ 0196-9999922222 Rate Sheet 01-01-20250196-99999222220196-9999922222
Sheet2
Cell Formulas
RangeFormula
C2:C5C2=MAP(A2:A5,LAMBDA(m,LET(t,TEXTSPLIT(m," "),CONCAT(XLOOKUP("*"&{"0196","0249"}&"*",t,t,"",2)))))
B2:B5B2=LET(t,TEXTSPLIT(A2," "),CONCAT(XLOOKUP("*"&{"0196","0249"}&"*",t,t,"",2)))
Dynamic array formulas.
 
Upvote 0

Forum statistics

Threads
1,225,743
Messages
6,186,777
Members
453,370
Latest member
juliewar

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