Digital Farmer
Digital Farmer

Reputation: 2107

Error using getRange + clear (Google Sheets & GAS)

When I use 'Page 1!A1:A' gives error in the script and does not clear all rows of COLUMN A.
But when I put 'Page 1!A1:A200' for example, it works perfectly.

But as the spreadsheet fluctuates in the number of rows, I cannot fix a value on the max quantity.

function Testes() {
  var ss = SpreadsheetApp.getActive();
  ss.getRange('Page 1!A1:A').clear({contentsOnly: true, skipFilteredRows: true});
};

How to adjust so that this no longer happens?

Upvotes: 0

Views: 39

Answers (1)

Cooper
Cooper

Reputation: 64072

function Testes() {
  var ss = SpreadsheetApp.getActive();
  var sh=ss.getSheetByName('Page 1');
  var rg=sh.getRange(1,1,sh.getLastRow(),1).clear({contentsOnly: true, skipFilteredRows: true});
}  

Upvotes: 1

Related Questions