I'm trying to apply one script that will run on an entire Google Sheets spreadsheet, not just one tab. I have multiple tabs all with the same format; I want the script to look at the data validation in column F for every tab and if "Not Applicable" is selected for any row, move the contents of that entire row to a tab called "Not Applicable Items"
I have no experience writing scripts, so I copied the script I'm currently using from a forum topic. It successfully moves the rows to the correct tab, but only for the specified active sheet. I want the script to look at the entire spreadsheet and move any row marked "Not Applicable."
How can I do this? Here's my code:
function onEdit() {
var sheetNameToWatch = "Floorplan + Calendars";
var columnNumberToWatch = 5; // column A = 1, B = 2, etc.
var valueToWatch = "Not Applicable";
var sheetNameToMoveTheRowTo = "Not Applicable Items";
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getActiveCell();
if (
sheet.getName() == sheetNameToWatch &&
range.getColumn() == columnNumberToWatch &&
range.getValue() == valueToWatch
) {
var targetSheet = ss.getSheetByName(sheetNameToMoveTheRowTo);
var targetRange = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
sheet
.getRange(range.getRow(), 1, 1, sheet.getLastColumn())
.moveTo(targetRange);
sheet.deleteRow(range.getRow());
}