Formula to extract certain text

rachel06

Board Regular
Joined
Feb 3, 2016
Messages
108
Office Version
  1. 365
Platform
  1. Windows
Hello

I'm trying to create a formula that will extract a text string from report names. What I'm needing to get out of the below is "REB000001". One issue I'm having is not all of those numbers have 9 characters. These file names should all be like this where the REB### is either going to be followed by a period or an underscore.

REB000001_Hospital System Inc_Calc Sheet_2023_Q3.xlsx
HOSPITAL SYSTEM INC_ REB000001_Rebate Summary.xlsx
max1539g_417517_HOSPITAL_SYSTEM_INC_ REB000001.xlsx
HOSPITAL_SYSTEM_INC_ REB000001_Remit.pdf

Thanks so much!!!
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
How about
Fluff.xlsm
AB
1
2REB000001_Hospital System Inc_Calc Sheet_2023_Q3.xlsxREB000001
3HOSPITAL SYSTEM INC_ REB000001_Rebate Summary.xlsxREB000001
4max1539g_417517_HOSPITAL_SYSTEM_INC_ REB000001.xlsxREB000001
5HOSPITAL_SYSTEM_INC_ REB000001_Remit.pdfREB000001
Data
Cell Formulas
RangeFormula
B2:B5B2=LET(a,TRIM(TEXTSPLIT(A2,{"_","."})),FILTER(a,EXACT("REB",LEFT(a,3))))
 
Upvote 1
One more option:
Excel Formula:
=TEXTBEFORE(MID(A2,FIND("REB",A2),LEN(A2)),{"_","."})
 
Upvote 1
The maximum length of a Windows filename is 255 characters, so you could drop the LEN function call and just use that.

=TEXTBEFORE(MID(A2,FIND("REB",A2),255),{"_","."})
 
Upvote 1
Solution
The maximum length of a Windows filename is 255 characters, so you could drop the LEN function call and just use that.

=TEXTBEFORE(MID(A2,FIND("REB",A2),255),{"_","."})
You're right.

I've realized you can also use TEXTAFTER.
Excel Formula:
="REB"&TEXTBEFORE(TEXTAFTER(A2,"REB"),{"_","."})
 
Upvote 1
Thank you all!! This is wonderful and way shorter than the find, mid, left, right monstrosity I was coming up with :)
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,221,417
Messages
6,159,789
Members
451,589
Latest member
Harold14

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