1

I'm trying to clear the contents of certain cells in the active sheet of my google sheets spreadsheet. Here's what I have so far:

function Reset() {
  var sheet = sheetName();
  var range = sheet.getRange("B4:G53");
  range.clearContent();
}

function sheetName(){ 
  return SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getName();
}

I get the error: TypeError: Cannot find function getRange in object Copy of 5.7.18. (line 4, file "Code")

What am I doing wrong? Thanks in advance.

0

The problem is that your variable sheet doesn't make reference to a Class Sheet object.

Change

return SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getName();

by

return SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.