Google Apps Script setFormula function

900 views Asked by At

I'm facing some issues with Googles Apps Script while using the following code to insert ArrayFormulas in 5 specific cells:

function AddForm() {
  
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  const sh=ss.getSheetByName('sheetname');
  var cell = sheet.getRange("Z2");
  cell.setFormula('=iferror(arrayformula(vlookup(J2:J,othersheetname!$L:$M,2,false)),"")');
  var cell = sheet.getRange("AA2");
  cell.setFormula('=iferror(arrayformula(vlookup(K2:K,othersheetname!$P:$Q,2,false)),"")');
  var cell = sheet.getRange("AB2");
  cell.setFormula('=iferror(arrayformula(vlookup(K2:K,othersheetname!$P:$Q,2,false)),"")');
} 

I'm getting a "ReferenceError: Run_AddForm is not defined" error message and don't understand why.

Can anyone help, please?

Thank you in advance for your kind support

Here's the call function that is still having issues:

function ManualSGAConso() {
 Run_MID2019();
 Run_2019SC();
 Run_MID2020();
 Run_AddForm();
}
1

There are 1 answers

7
Marios On BEST ANSWER

First of all, you made a small mistake in the AddForm() function:

sh should be sheet

  function AddForm() {
  
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  const sheet=ss.getSheetByName('sheetname');
  var cell = sheet.getRange("Z2");
  cell.setFormula('=iferror(arrayformula(vlookup(J2:J,othersheetname!$L:$M,2,false)),"")');
  var cell = sheet.getRange("AA2");
  cell.setFormula('=iferror(arrayformula(vlookup(K2:K,othersheetname!$P:$Q,2,false)),"")');
  var cell = sheet.getRange("AB2");
  cell.setFormula('=iferror(arrayformula(vlookup(K2:K,othersheetname!$P:$Q,2,false)),"")');
} 

Since the error message you are getting is looking for the Run_AddForm() function, try to replace Run_AddForm() with AddForm():

function ManualSGAConso() {
 Run_MID2019();
 Run_2019SC();
 Run_MID2020();
 AddForm();
}