Search code examples
google-apps-scriptgoogle-sheetsgoogle-formsformulas

Trouble logging formulas


I'm using a sheet to reference a separate spreadsheet collecting responses from a Google Form. I want to log the rows as values once they are populated and maintain the formula in the rows that don't yet contain a value. However when I run the script nothing happens. This seems like it should be straightforward.

function setFormulas() {
  var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("English Form Responses");
  Logger.log(ss.getRange(2, 1, ss.getLastRow(), 16).getValues());
}

Solution

  • the Range.getValues(); function doesn't return formulas, only values. Use Range.getFormulas(); to get / log the formulas in a range.

    https://developers.google.com/apps-script/reference/spreadsheet/range#getFormulas()