Google Sheet AppScrip setFormula Syntax error: SyntaxError: missing )

Viewed 119

i cant get what im missing with my script (newbie, non-coder, I only get the script in google) here is my script.

GOOGLE SHEET appscript

var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("INVENTORY OUT");
ss.getRange("B2").setFormula("=IFERROR(VLOOKUP(I:I,'get sloc for picklist'!A:B,2,0),"NO STOCKS")");

error message:

Syntax error: SyntaxError: missing ) after argument list line: 52 file: ADD_1.gs

2 Answers

Solution:

The solution would be to use template literals:

function myFunction() {
  var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet15"); 
  ss.getRange("B2").setFormula(`=IFERROR(VLOOKUP(I:I,'get sloc for picklist'!A:B,2,0),"NO STOCKS")`);
}

In this way everything that is enclosed by the backticks (``) is considered as a type of string.

You cannot use single quotes in your formula definition that is already enclosed in quotes!

ss.getRange("B2").setFormula("=IFERROR(VLOOKUP(I:I,'get sloc for picklist'!A:B,2,0),\"NO STOCKS\")");
Related