I am new to Google script so apologies if this question has already been answered.
I have a spreadsheet with multiple worksheets a number of which have a status column on them somewhere.
Using code I have already found I am able set the entire row colour depending on the value in the cell in the the status column.
The problem I have is that I can only get the code to work on a single sheet.
The following code (by ScampMichael) works exactly as I want upating an entire row based on the value in the Status column but I cannot get it to work on multiple sheets (with different names) in the same workbook.
I have tried the code as seperate scripts with edited sheet names and column numbers so that each refers to an individual sheet but still only 1 sheet is updated.
Please can someone advise how I can edit this code or how I can duplicate it so that works across multiple sheets ?
function onEdit(e) {
var statusCol = 2; // replace with the column index of Status column A=1,B=2,etc
var sheetName = "Services"; // replace with actual name of sheet containing Status
var cell = e.source.getActiveCell();
var sheet = cell.getSheet();
if(cell.getColumnIndex() != statusCol || sheet.getName() != sheetName) return;
var row = cell.getRowIndex();
var status = cell.getValue();
// change colors to meet your needs
var color;
switch(status ) {
case "Down":
color = "red";
break;
case "":
color = "White";
break;
case "Up":
color = "green";
break;
}
sheet.getRange(row + ":" + row ).setBackgroundColor(color);
}
Thank you.