In Google Sheets, I have found and edited code that allows me to delete rows if a cell value in a specified column is 0 or blank. I want to run this same task across 2 of the 4 sheets in my spreadsheet. How do I edit the code to have it function in multiple sheets simultaneously. The 2 sheets are not related, but I have it structured so the same column will be searched in both sheets for the 0.
function readRows() {
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] == 0 || row[4] == '') {
sheet.deleteRow((parseInt(i)+1) - rowsDeleted);
rowsDeleted++;
}
}
};
google.script.run.functionName()
Thegoogle.script.run
thing is called "Client Side API." You can not cause code in the server to run multiple instances of a function from the server. The difference is whether it's triggered from the client or from the server. If you really don't care about running the same function simultaneously, but you just want it to work on different sheet tabs, you can get the sheet tab by name.ss.getSheetByName()
– Alan Wells