How can I change the cell background color based on the cell's content in an onEdit()
function?
I've had many versions of code that I tested for this - some working almost right, some not working at all. But I have yet to get this to work the way I need it to.
Please forgive the lack of elegance in the way that this is written, but I actually need to keep the code as straightforward as possible since there will be many cell changes, many conditionals, and many differing numbers of cells that will be changed depending on what gets changed on the worksheet.
Ok, so here goes...
function onEdit(event)
{
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet2");
var changedCell= event.source.getActiveRange().getA1Notation();
if (changedCell == 'B3') {
var c = ss.getRange("B3").getValue();
if (c < 2); {
ss.getRange("B3").setBackgroundColor('#ff0000');
ss.getRange("B12").setBackgroundColor('#ff0000');
}
if (c > 1); {
ss.getRange("B3").setBackgroundColor('#000000');
ss.getRange("B12").setBackgroundColor('#000000');
}
}
}