Trying to optimize this function to find numbers after a specific text

Rnkhch

Well-known Member
Joined
Apr 28, 2018
Messages
528
Office Version
  1. 365
Platform
  1. Windows
Hello,

I found this formula online and adapted it to some extent, and I'm trying to figure out how it works, but also why I get some strange results.

My goal is to find and extract only the numbers that occur after a specific text in a string, in this case the word "day". So in this example, I need the output to be "1". I don't want the numbers that are further to the right of the numbers that are closest to "day". Here in the case of A8, I get a strange output, and wonder why.

Of course, if there are other better formulas, please let me know as well.

Book1
ABCD
1dfeDay1 gh23gew1
2Day 1 gh23gew451
3gejxqwqDay 1gh23gew1
4dfegejday 1 )gh23gew1
5dfegej32day 1 )gh23gew1
6dfegej32gh23gewDay 11
7dfegej32gh23gewDay 1a1
8j32gh23gewDay 1 an0.041667
9j32gh23gewDay 1an1
10dfeDay-1 gh23gew31
11dfeDay-1 -gh23gew1
12dfeDay-(1) -gh23gew1
13
Sheet1
Cell Formulas
RangeFormula
C1:C12C1=LOOKUP(10^6,1*MID(A1,MIN(FIND({0,1,2,3,4,5,6,7,8,9},A1&"0123456789",SEARCH("Day",""&A1&""))),{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25}))


Thanks for any input!
 
Yes, they have been single because I've been using UNIQUE which causes the FILTER to not spill.
Not if there's more than one unique value.
This question was specifically for your XLOOKUP formula which gives an error for those instances when there are multiple identical matches ...
It won't error. It will find the first occurrence. If the other occurrences are identical, this will be the same value that UNIQUE/FILTER returns. XLOOKUP will only be a problem if you have more than one unique value to return.

I'd keep it simple and transparent, and avoid monster formulae. If your individual cell formulae in A:A might spill, create space to let them spill across the adjacent column(s). Then just point your GetDayNo formula to the individual cells. If you have 2, 3 ... + values for any one row, you'll need to decide what to do with them.
 
Last edited:
Upvote 0

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
I either have one single match, or multiple matches that are identical
If that is the case, then you should be able to resolve the UNIQUE(FILTER.. issue by INDEXing the first value.

Excel Formula:
=LET(
txt,INDEX(UNIQUE(FILTER(FMBMcReqDay,(FMBMcGeqSID=B35)*(FMBMcIeqReq=D35)*(ISNUMBER(SEARCH("sample",FMBMcL)))*(ISNUMBER(SEARCH("sputum",FMBMcPeqSpec)))*(ISNUMBER(SEARCH("Day",FMBMcReqDay))))),1),
r,REPLACE(txt,1,SEARCH("day",txt),""),
ch,MID(r,SEQUENCE(LEN(r)),1),
LEFT(SUBSTITUTE(TRIM(CONCAT(IF(ISNUMBER(ch+0),ch," ")))," ",REPT(" ",20)),20)+0)
 
Upvote 0
If that is the case, then you should be able to resolve the UNIQUE(FILTER.. issue by INDEXing the first value.
I tested that earlier with a simpler FILTER construction.

INDEX( ... ,1,1) seems to do the trick.
 
Upvote 0
I see, thank you both, for the directions/formulas. I'll test and update.

Tomorrow is grand jury day 🤦‍♂️, so I'll test on Thursday at work 🍻
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,592
Members
449,089
Latest member
Motoracer88

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