Search code examples
excelvbaexcel-formulasumifs

Is there an excel formula that I can use to sum all blue font numbers from a string in one cell to another?


I'm trying to sum all numbers in a string that appear in parentheses from one cell to another.

There is other alphanumeric characters, so I've used some VBA code I found to change all items within parentheses to the color blue. Now I'd like to sum all those numbers into another cell, and have it update automatically.

I'm using Kutools add-in for Excel, and I tried the sumbyfontcolor, but that is for a range, whereas I'm only referencing one cell.

Here's one of the cell's contents that I'd like to extract and sum the numbers from:

SM($20.00),RCP($25.65),PMP($612.50)12.25 Hrs T-2,M-7.25,S/G-1.5,Insp/Assy-1.5,C&R($65.00)

The example above doesn't show it, but the dollar amounts are in blue:

image of cell


Solution

  • Here is an array formula that will parse the string and add the numbers contained inside the ()

    =SUM(IFERROR(--TRIM(MID(SUBSTITUTE(A1,"(",REPT(" ",999)),(ROW($A$1:INDEX($A:$A,LEN(A1)-LEN(SUBSTITUTE(A1,"(","")))))*999+1,FIND(")",MID(SUBSTITUTE(A1,"(",REPT(" ",999)),(ROW($A$1:INDEX($A:$A,LEN(A1)-LEN(SUBSTITUTE(A1,"(","")))))*999+1,999))-1)),0))
    

    Being an array formula it needs to be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode.

    enter image description here