Extracting numbers from a string and adding them up

Vector8086

New Member
Joined
Jan 4, 2022
Messages
20
Office Version
  1. 365
  2. 2021
  3. 2016
  4. 2007
Platform
  1. Windows
  2. Web
I saw an old post where with the below formula to extract numbers from a string containing alphanumeric values - something like "p2, e(3), 15ip"

This will return: 2315.

My question is, can this be modified to return the sum of these numbers, i.e. 20? And can A1 be a range of cells where all the resulting numbers are added up?

Code:
B1: =SUMPRODUCT(MID(0&A1,LARGE(INDEX(ISNUMBER(--MID(A1,ROW($1:$25),1))*
ROW($1:$25),0),ROW($1:$25))+1,1)*10^ROW($1:$25)/10)

Thanks in advance!
V
 
Your profile is showing you have XL365, XL2021 and XL2007... where did the XL2016 come from????
I'm just reading the product details on the computer I'm currently using. :)
1697834299412.png
 
Upvote 0

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try this in your copy of XL365...
Excel Formula:
=SUM(0+TEXTSPLIT(TRIM(CONCAT(IFERROR(0+MID(A1,SEQUENCE(LEN(A1)),1)," ")))," "))
This does the job in XL365. If it could take in a cell range, like A1:A2 or (A1,A3,A5) that would be awesome.
 
Upvote 0
This does the job in XL365. If it could take in a cell range, like A1:A2 or (A1,A3,A5) that would be awesome.
The following formula can do a contiguous range (such as A1:A5), but I it cannot (and I don't think it is possible) do a discontiguous range (like A1,A3,A5)
Excel Formula:
=MAP(A1:A5,LAMBDA(x,IF(x="","",SUM(0+TEXTSPLIT(TRIM(CONCAT(IFERROR(0+MID(x,SEQUENCE(LEN(x)),1)," ")))," ")))))
 
Upvote 1
Try this in your copy of XL365...
Excel Formula:
=SUM(0+TEXTSPLIT(TRIM(CONCAT(IFERROR(0+MID(A1,SEQUENCE(LEN(A1)),1)," ")))," "))

Sticking with XL365 I could use the TEXTJOIN function to expand this formula from a single cell to a list of ranges. I also added a dummy "0," to cover the case of a single blank cell.
Excel Formula:
=SUM(0+TEXTSPLIT(TRIM(CONCAT(IFERROR(0+MID(TEXTJOIN(",",TRUE,A1,A3,"0,"),SEQUENCE(LEN(TEXTJOIN(",",TRUE,A1,A3,"0,"))),1)," ")))," "))
 
Upvote 0
Sticking with XL365 I could use the TEXTJOIN function to expand this formula from a single cell to a list of ranges. I also added a dummy "0," to cover the case of a single blank cell.
Excel Formula:
=SUM(0+TEXTSPLIT(TRIM(CONCAT(IFERROR(0+MID(TEXTJOIN(",",TRUE,A1,A3,"0,"),SEQUENCE(LEN(TEXTJOIN(",",TRUE,A1,A3,"0,"))),1)," ")))," "))
Did you see my last post (posted 2 to 3 minutes before your post above)?
 
Upvote 1
Solution
The following formula can do a contiguous range (such as A1:A5), but I it cannot (and I don't think it is possible) do a discontiguous range (like A1,A3,A5)
Excel Formula:
=MAP(A1:A5,LAMBDA(x,IF(x="","",SUM(0+TEXTSPLIT(TRIM(CONCAT(IFERROR(0+MID(x,SEQUENCE(LEN(x)),1)," ")))," ")))))
This returns the individual 5 sums from A1:A5. It ends up taking 5 spaces, and not combining the sums. Your original formula works better for me.
 
Upvote 0
I just tried it, but the first formula is better.
Which first formula... mine? If so, the last formula I posted is my first formula, just bundled in other function calls so it can process all cells in a contiguous range at the same time instead of one at a time like my first formula.
 
Upvote 0
Which first formula... mine? If so, the last formula I posted is my first formula, just bundled in other function calls so it can process all cells in a contiguous range at the same time instead of one at a time like my first formula.
Yes. A modified version of it:
=SUM(0+TEXTSPLIT(TRIM(CONCAT(IFERROR(0+MID(TEXTJOIN(",",TRUE,A1,A3,"0,"),SEQUENCE(LEN(TEXTJOIN(",",TRUE,A1,A3,"0,"))),1)," ")))," "))
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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