Is there a way to evaluate a formula that is stored in a cell?

Michael Krupp picture Michael Krupp · Apr 30, 2013 · Viewed 28.6k times · Source

In a Google Docs spreadsheet, I'm looking for something like =EVAL(A1) where A1 is set to "=1+2".

I found out that in MS Excel there is an EVALUATE() function (which seems a bit tricky to use properly). But I could not find anything similar in Google Docs.

I also searched through the function list, but could not find anything helpful...

Answer

Mogsdad picture Mogsdad · Apr 30, 2013

No, there's no equivalent to Excel's EVALUATE() in Google Sheets.

There's long history behind this one, see this old post for instance.

If you're just interested in simple math (as shown in your question), that can be done easily with a custom function.

function doMath( formula ) {
  // Strip leading "=" if there
  if (formula.charAt(0) === '=') formula = formula.substring(1);
  return eval(formula)
}

For example, with your A1, put =doMath(A1) in another cell, and it will be 3.