Formula for extracting multiple occurrences of text substring in a cell

EmLearnsMicrosoft

New Member
Joined
Jun 28, 2024
Messages
11
Office Version
  1. 365
Platform
  1. MacOS
Hi! I am trying to write a formula that will allow me to extract multiple strings of numbers from one cell to another, while filtering out all other irrelevant text from the source cell. For example (see attached photo), I want to be able to extract multiple 8-digit numbers, separated into the output column by "; ", that each occur after the text "ABCD: " within a cell. I have tried multiple complex nesting functions, based off of suggestions on other similar issues, but cannot seem to tailor the functions to fit my exact needs. Any help would be appreciated!!! (I use Excel for Mac, Version 16.84 (24041420))

Book2.xlsx
AB
1Data Column 1ABCD values extracted
2Apple 2021 (ABCD: 12345678)12345678
3Boater 2021 (ABCD: 23456789), Crayon 2017 (ABCD: 34567890), Dorito 2010 (ABCD: 45678901), Developer Website: Grannies Cookies23456789; 34567890; 45678901
4Moose: Study immunity and effectiveness of Sample A (Apple 2021)
5Moose: evaluate immunogenicity (Elbows 2021 (ABCD: 56789012)) Moose: evaluate infectivity, safety, immunogenicity and protective efficacy (Freefall 2021 (PMID: 67890123))56789012; 67890123
Sheet1
 

Attachments

  • Screenshot 2024-06-28 at 3.43.59 PM.png
    Screenshot 2024-06-28 at 3.43.59 PM.png
    80.3 KB · Views: 18
There must been some similar instances, but this will check if the numeric string is 8 characters long.
Excel Formula:
=UNIQUE(
   TEXTSPLIT(TEXTJOIN(";",,MAP(A2:B3,LAMBDA(m,
      LET(t,TEXTSPLIT(m,,{" ",")"},1),d,DROP(t,1),TEXTJOIN(";",,IF(ISNUMBER(FIND(":",DROP(t,-1)))*ISNUMBER(--d)*(LEN(d)=8),d,"")))))),,";"))



Data range.
Thank you so much for your ongoing help. This formula populated a "#VALUE" error and says "Error in Value". When I "Trace Error", it takes me to the very first cell in the array. The contents of that cell are as follows: "Tim 2021 (ABCD: 34925355)"
 
Upvote 0

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Try this option as well. This doesn't rely on TEXTJOIN so it won't have a limit.
Excel Formula:
=UNIQUE(TOCOL(
      DROP(
           REDUCE("",TOCOL(A2:B3,1),LAMBDA(a,m,VSTACK(a,LET(t,TEXTSPLIT(m,,{" ",")"},1),d,DROP(t,1),IFS(ISNUMBER(FIND(":",DROP(t,-1)))*ISNUMBER(--d)*(LEN(d)=8),d))))),
      1),
2))
This formula populates a "#CALC" error and further says "Empty Array"
 
Upvote 0
Unfortunately it seems as though I do not yet have access to these functions (I updated the software today and tried).
It's only available on the Beta server right now.

This formula populates a "#CALC" error and further says "Empty Array"
Are you using Excel or Google Sheets? I've never seen that in Excel.
Book2
ABCD
1Data Column 1
2Tim 2021 (ABCD: 34925355)Moose: Study immunity and effectiveness of Sample A (Apple 2021)34925355
3Boater 2021 (ABCD: 23456789), Crayon 2017 (ABCD: 34567890), Dorito 2010 (ABCD: 45678901), Developer Website: Grannies CookiesMoose: evaluate immunogenicity (Elbows 2021 (ABCD: 56789012)) Moose: evaluate infectivity, safety, immunogenicity and protective efficacy (Freefall 2021 (PMID: 67890123))23456789
434567890
545678901
656789012
767890123
Sheet3
Cell Formulas
RangeFormula
D2:D7D2=UNIQUE(TOCOL( DROP( REDUCE("",TOCOL(A2:B3,1),LAMBDA(a,m,VSTACK(a,LET(t,TEXTSPLIT(m,,{" ",")"},1),d,DROP(t,1),IFS(ISNUMBER(FIND(":",DROP(t,-1)))*ISNUMBER(--d)*(LEN(d)=8),d))))), 1), 2))
Dynamic array formulas.
 
Upvote 0
It's only available on the Beta server right now.


Are you using Excel or Google Sheets? I've never seen that in Excel.
Book2
ABCD
1Data Column 1
2Tim 2021 (ABCD: 34925355)Moose: Study immunity and effectiveness of Sample A (Apple 2021)34925355
3Boater 2021 (ABCD: 23456789), Crayon 2017 (ABCD: 34567890), Dorito 2010 (ABCD: 45678901), Developer Website: Grannies CookiesMoose: evaluate immunogenicity (Elbows 2021 (ABCD: 56789012)) Moose: evaluate infectivity, safety, immunogenicity and protective efficacy (Freefall 2021 (PMID: 67890123))23456789
434567890
545678901
656789012
767890123
Sheet3
Cell Formulas
RangeFormula
D2:D7D2=UNIQUE(TOCOL( DROP( REDUCE("",TOCOL(A2:B3,1),LAMBDA(a,m,VSTACK(a,LET(t,TEXTSPLIT(m,,{" ",")"},1),d,DROP(t,1),IFS(ISNUMBER(FIND(":",DROP(t,-1)))*ISNUMBER(--d)*(LEN(d)=8),d))))), 1), 2))
Dynamic array formulas.
I'm using Excel. When I select "Help on this error" it says "#CALC! errors occur when Excel's calculation engine encounters a scenario it does not currently support."
Screenshot 2024-07-11 at 4.30.47 PM.png
 
Upvote 0
Can you show exactly what you entered and your sheet?
Sure; what all on the sheet do you need to see? The array of data is large (B2:DT211) so won't be able to share everything

Here's are the formula's though (copy & pasted straight from excel):

1. The one that resulted in a #VALUE error:
=UNIQUE(TEXTSPLIT(TEXTJOIN(";",,MAP(B2:DT211,LAMBDA(m,LET(t,TEXTSPLIT(m,,{" ",")"},1),d,DROP(t,1),TEXTJOIN(";",,IF(ISNUMBER(FIND(":",DROP(t,-1)))*ISNUMBER(--d)*(LEN(d)=8),d,"")))))),,";"))

2. The one that resulted in a #CALC! error:
=UNIQUE(TOCOL(DROP(REDUCE("",TOCOL(B2:DT211,1),LAMBDA(a,m,VSTACK(a,LET(t,TEXTSPLIT(m,,{" ",")"},1),d,DROP(t,1),IFS(ISNUMBER(FIND(":",DROP(t,-1)))*ISNUMBER(--d)*(LEN(d)=8),d))))),1),2))
 
Upvote 0
Your list is probably too long and exceeds the row limit in Excel. Try it with a smaller range and see if that's the issue.
 
Upvote 0
You're welcome. I'd go with the second formula as it's less restrictive.
 
Upvote 0
For now regular expression functions are available for insider users (Beta Channel). Here's the news about them.
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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