Google-sheets – Sending formulas with Google Forms

google sheetsgoogle-forms

I'm trying to give a formula using the equal sign, when submitting a Short answer in a Google Form. If I'm writing

=6+3

into the form and then submit it, I get the string

'=6+3

in the Google Sheet Response sheet. It does not seem to calculate this function automatically.

When trying to getValue() this cell, I cannot find the quote, and so I cannot execute this function.

Does anyone have any good idea to solve this problem? Is it possible to execute this function in the Response sheet?

Best Answer

The following function gets the active range value and set it as the active cell formula:

function stringToFormula() {
  var rng = SpreadsheetApp.getActiveRange();
  var value = rng.getValue();
  rng.setFormula(value);
}

If the cell value is '=6+7 the cell formula will be =6+7 and the cell display value will be 13