# Sum certain numbers in a range of cells that contain text and numbers

I've got a range of cells in Google Sheets that contain a mixture of text and numbers, or just text, or even blank cells. For example:

• Yes 32
• Yes 46
• Yes
• No 1
• No
• Apologies 23
• Apologies
• n/a
• (and blank cells)

I want the sum of just the numbers in cells that contain the word 'Yes' as well as a number. So in the above list of example values, I'd want the sum of 32 + 46 = 78.

I am currently using this formula, which came from this question:

``````=ARRAYFORMULA(SUM(--REGEXEXTRACT(P4:ZZ4,"(\d+)")))
``````

This formula works fine if all the cells contain numbers, but I now need it to ignore the cells that don't contain numbers or are blank, hence this new question.

The above formula gives me errors like this for cells that don't contain numbers:

Error Function REGEXEXTRACT parameter 2 value "(\d+)" does not match text of Function REGEXEXTRACT parameter 1 value "Apologies".

Guarding your regexextract() with a regexmatch() should help:

``````=ARRAYFORMULA(
IF(REGEXMATCH(P4:ZZ4, "(\d+)"),
SUM(--REGEXEXTRACT(P4:ZZ4,"(\d+)")),
""
)
)
``````

Since there's a space between `Yes` and `32`, to sum up all numbers:
``````=SUMPRODUCT(INDEX(SPLIT(C1:C8," "),,2))
To sum up only `Yes`:
``````=SUMPRODUCT(IF(REGEXMATCH(C1:C8,"Yes"),INDEX(SPLIT(C1:C8," "),,2)))