Reputation: 5
I have cells in my spreadsheet who are like:
RF(4);MN(4);LL(2);TE(4);HA(2)
There is a formula where I can sum all the numbers in that String/Cell?
I can try another way by Office Script, but since he has low speed, and I have to sum a lot of lines of cells with those type of string, i would try to accelerate the process with Excel Formula as much as possible.
best regards
Upvotes: 0
Views: 2598
Reputation: 152450
With Excel 2013 and later you can use FILTERXML to pull out the numbers and wrap that in SUMPRODUCT to return the sum:
=SUMPRODUCT(FILTERXML("<t><s>"&SUBSTITUTE(SUBSTITUTE(A1,")","</s><s>"),"(","</s><s>")&"</s></t>","//s[number()=.]"))
One note, this does not work in Excel online or the phone/tablet apps. And some versions of mac also do not have FILTERXML.
If they are always single digit we can use:
=SUMPRODUCT(IFERROR(--MID(A1,SEQUENCE(LEN(A1)),1),0))
or older version:
=SUMPRODUCT(IFERROR(--MID(A1,ROW($ZZ$1:INDEX($ZZ:$ZZ,LEN(A1))),1),0))
For some versions this will require the use of Ctrl-Shift-Enter instead of Enter when exiting edit mode to make it an array formula.
Upvotes: 4
Reputation: 2584
Data
--> Text to Columns
--> Delimit / Next
--> Semicolon
--> Finish
A2:E2
and downward, placing this formula in F2:J2
=SUMPRODUCT(MID(0&A2, LARGE(INDEX(ISNUMBER(--MID(A2, ROW(INDIRECT("1:"&LEN(A2))), 1)) * ROW(INDIRECT("1:"&LEN(A2))), 0), ROW(INDIRECT("1:"&LEN(A2))))+1, 1) * 10^ROW(INDIRECT("1:"&LEN(A2)))/10)
This should be able to handle multiple digits in a single group of parenthesis. You can avoid having all the additional columns, by adding the formula for each column together. I just break this out so if there's issues you have visibility in what's happening and how it works.
Upvotes: 0