This is sort of a two part questions.
First I need help writing this script, and then I need help with implementing a script in Google spreadsheets.
What I want to do is to change the background color of a cell (to red) if the number contained in that cell is over 40 (hours). For my spreadsheet I have 7 day columns, each with an in and an out column under them. I use a formula in the total column of the spreadsheet to subtract the value of the out time from the in time, and then add that number to the next cell until I get to the total. So that is the column that I want to apply this script to. I can write a little bit of JS, but I don't really know how to connect it to a spreadsheet instead of a website.
Here is my basic idea on how this should work:
//Trying to get a script that will change the background color to red if hours are over 40.
function onEdit(e) {
var cellID = e.source.getActiveCell();
var cellValue = e.cell.getValue(); //I may need to slice out the numbers before the first : for this to work..not sure b/c i cant get this to debug. Also not sure that I need this function, maybe can just do var cellValue = cellID.value or just use cellID.value ?
if (cellValue > 40 ) {
cellID.setBackgroundColor('red');
} else {
cellID.setBackgroundColor('white');
}
}
Not real sure about the onEdit function..would rather have it be my own function but I'm not sure what kind of listener to tie it to. Also, if you guys can help me out with the general idea of this thing should work I can probably tweak it to make it work with my specific spreadsheet. Really what I need to know is what i should be listening for on my spreadsheet, and how to actually attach the script to the spreadsheet.