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
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Try this in your copy of XL365...
Excel Formula:
=SUM(0+TEXTSPLIT(TRIM(CONCAT(IFERROR(0+MID(A1,SEQUENCE(LEN(A1)),1)," ")))," "))
 
Upvote 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.
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
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
Hi,

Like this?
Excel Formula:
=SUMPRODUCT(MID(0&A1,LARGE(INDEX(ISNUMBER(--MID(A1,ROW($1:$25),1))*ROW($1:$25),0),ROW($1:$25))+1,1)+0)
 
Upvote 0
Hi
Excel Formula:
=SUM(--TEXTSPLIT(TRIM(CONCAT(TEXT(MID(A1,SEQUENCE(99),1),"0,,0, ")))," "))
 
Upvote 0
Hi,

Like this?
Excel Formula:
=SUMPRODUCT(MID(0&A1,LARGE(INDEX(ISNUMBER(--MID(A1,ROW($1:$25),1))*ROW($1:$25),0),ROW($1:$25))+1,1)+0)
Hi! Thanks for the help. This one is not adding the last number properly. I'm getting 11. It looks like it's adding only the single numbers. The sum should be 2+3+15 =20.
 
Upvote 0
Hi
Excel Formula:
=SUM(--TEXTSPLIT(TRIM(CONCAT(TEXT(MID(A1,SEQUENCE(99),1),"0,,0, ")))," "))
Thank you for the formula. My version of Excel (2016) doesn't seem to include the SEQUENCE function. So, I'm getting an error.
 
Upvote 0
Aahh you are looking for 15, not 1+5. Sorry. I don't know. Maybe you should wait for other replies.
 
Upvote 0
Aahh you are looking for 15, not 1+5. Sorry. I don't know. Maybe you should wait for other replies.
Right. The numbers that are together have to be treated as a single value. Thanks for the help though!
 
Upvote 0

Forum statistics

Threads
1,215,617
Messages
6,125,867
Members
449,266
Latest member
davinroach

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