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:


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".


2 Answers 2


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

  IF(REGEXMATCH(P4:ZZ4, "(\d+)"),

If it doesn't, please provide a link to an example spreadsheet.


Since there's a space between Yes and 32, to sum up all numbers:


To sum up only Yes:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.