How to use a formula written as a string in another cell [evaluate for Google Spreadsheet] [duplicate]

Short answer

Use a script that includes something like var formula = origin.getValue() to get the string and something like destination.setFormula(formula) to return the formula.

Explanation

As was already mentioned by the OP, Google Sheets doesn’t have a EVALUATE() built-in function. A custom function can’t be used because custom functions can only return one or multiple values but can’t modify other cell properties.

A script triggered by a custom menu, events or from the Google Apps Script editor could be used to update the formulas of the specified cells.

Since the formulas will be kept as strings, it could be more easy to keep them in the script rather than in the spreadsheet itself.

Example

The following is a very simple script that adds the specified formula to the active range.

function addFormula() {
  var formula="=UNIQUE(C1:C5)";
  var range = SpreadsheetApp.getActiveRange();
  range.setFormula(formula);
}

Leave a Comment