How do I run this script on a particular sheet instead of the entire spreadsheet?
function deleteQCOrder() {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
var values = rows.getValues();
var rowsDeleted = 0;
for (var i = 0; i <= numRows - 1; i++) {
var row = values[i];
if (row[4] == 'Delete' || row[4] == '') { // This searches all cells in columns A (change to row[1] for columns B and so on) and deletes row if cell is empty or has value 'delete'.
sheet.deleteRow((parseInt(i)+1) - rowsDeleted);
rowsDeleted++;
}
}
};
For instance, if I want to run it on "Sheet1", I tried:
function deleteQCOrder() {
var sheet = SpreadsheetApp.getActiveSheet();
var ss = sheet.getSheetByName('Sheet1');
var rows = ss.getDataRange();
var numRows = rows.getNumRows();
var values = rows.getValues();
var rowsDeleted = 0;
for (var i = 0; i <= numRows - 1; i++) {
var row = values[i];
if (row[4] == 'Delete' || row[4] == '') { // This searches all cells in columns A (change to row[1] for columns B and so on) and deletes row if cell is empty or has value 'delete'.
sheet.deleteRow((parseInt(i)+1) - rowsDeleted);
rowsDeleted++;
}
}
};
but instead of running, I get this error:
TypeError: Cannot find function getSheetByName in object Sheet. (line 3, file "Delete-Order-No.")