1

I am trying to create an Apps Script function to update the new data at the last row of a range in Google Sheet. My sheet "import" is currently empty and I have the following error when I add my function ImportPrivacyTagCo() into A1 cell : "Exception: Range not found".

function ImportPrivacyTagCo() {
  
var cellVal= '=IMPORTJSON("myAPIurl")';

 var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('import');
 var lastrow = sheet.getLastRow() + 1

sheet.getRange(lastrow).setValues([cellVal]);

}

Do you have any idea to fix this error ? Many thanks

Sébastien
  • 11
  • 1

1 Answers1

1

Look at how the .getRange() is working.

You need to add the column number. Also it looks like you want to set a formula In that case, use .setFormula() instead.

function ImportPrivacyTagCo() {
  
var cellVal= '=IMPORTJSON("myAPIurl")';

 var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('import');
 var lastrow = sheet.getLastRow() + 1

sheet.getRange(lastrow, 1).setFormula(cellVal)

}
RemcoE33
  • 1,551
  • 1
  • 4
  • 11