Google Sheets Formulas – Sum Values Inside Multiple Brackets in a Single Cell

google sheets

as mention on the title, I am stuck to sum all the value inside multiple brackets within single cell in Google Spreadsheet.

Below is the query that must store within single cell:
26b(1), 26a(41), 27b2(17)

Basically, the value that I want is "59" ( sum of number 1, 41 and 17 ).

Note: if the query above is impossible to find, how about storing the value after equal such as 26b=1, 26a=41, 27b2=17

Best Answer

Formula

=ArrayFormula(SUM(VALUE(REGEXEXTRACT(SPLIT(A1,","),"\((\d{1,})\)"))))

Brief explanation

We could use regular expressions on Google Sheets but it's support is limited. Fortunately Google Sheets has other features that could help to overcome those limitations.

The SPLIT function splits the cell value on A1 using a comma as separator. Using ArrayFormula makes REGEXTRACT able to take the SPLIT resulting array as argument and to apply the regular expression to each array member. The result is an array of texts, so VALUE is used to convert them to numbers and finally the SUM function sums those numbers.


From REGEXEXTRACT

Notes

  • Google products use RE2 for regular expressions. Google Sheets supports RE2 except Unicode character class matching. Learn more on how to use RE2 expressions.
  • This function only works with text (not numbers) as input and returns text as output. If a number is desired as the output, try using the VALUE function in conjunction with this function. If numbers are used as input, convert them to text using the TEXT function.