Extract multiple values from text

ian0411

New Member
Joined
Aug 17, 2012
Messages
18
Say I have a string in cell A1 as this: TestA(2h)TestB(15h)TestC(4H), and I would like to extract the numbers and sum them up. For this example, I want 2 + 15 + 4 = 21. Is it possible to do this with only Excel formula and no VBA?

I currently have this array formula from another post but it won't quite work for this scenario (it gets 12 = 2 + 1 + 5 + 4).
Code:
{=SUM(VALUE(MID(0&A1,LARGE(ISNUMBER(--MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1))*ROW(INDIRECT("1:"&LEN(A1))),ROW(INDIRECT("1:"&LEN(A1))))+1,1)))}

Also, those numbers will always be surrounded by (xxh), xx means values.

Thanks,

Ian
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Hi, here is one option you can try:


Excel 2013/2016
AB
1TestA(2h)TestB(15h)TestC(4H)21
Sheet1
Cell Formulas
RangeFormula
B1=SUMPRODUCT(0+("0"&TRIM(MID(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(LOWER(A1),"h",""),")","("),"(",REPT(" ",999)),ROW(INDIRECT("1:20"))*2*999-998,999))))
 
Upvote 0
@FormR, can I ask you for help again with another string?

TestA (2h) TestB (15h) TestC (draft) (13H)

Now I have another string with no number but still in the parentheses. Don't know how to do it correctly.
 
Last edited:
Upvote 0
Upvote 0
@FormR, you know what. I also got the same formula as you did. Guess I am getting better. Haha. But I really appreciated your quick response and your precious time for getting back to me. Have a great day.
 
Upvote 0

Forum statistics

Threads
1,215,046
Messages
6,122,852
Members
449,096
Latest member
Erald

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