Google Sheets – Sum Cells with Numbers and Text

formulasgoogle sheets

This has already been addressed in Excel but I was wondering how to do the same in Google Sheets.

So suppose the B cell has this formula:

="frontend (days)
total: "&sum(B2,B10,B14,B20)

and the C cell has a similar formula. I would like the D cell to add the numbers in those two cells.

WA92983 Q example

Ideas?

Best Answer

try this:

=REGEXEXTRACT(B1,"\d+\.?\d+$|\d+")*1+REGEXEXTRACT(C1,"\d+\.?\d+$|\d+")*1

REGEXEXTRACT part of formula "\d+.?\d+$" does this:

  • \d - match and retun digit from 0 to 9
  • \d+ - gives one or more digits
  • . - any symbol
  • \. - dot
  • ? - makes previous symbol optional (we use it here to match integers)
  • $ - matches end of string
  • | - OR

Update 2016/09

In some cases you may need to use different regular expressions and formulas. For example, if we have the text total = $1,734.00 and want to get 1734, we need this formula:

=REGEXREPLACE(F1,"[^\d]","")/100

this formula does the following:

  • replace all symbols except digits
  • divide by 100 because we get number 173400 in first operation