I have the below script working fine on my "Order sheet" (project name is "Order sheet code" file is "Code.gs")
function onEdit(e) {
var sheet = e.source.getActiveSheet();
var activeCell = sheet.getActiveCell();
var col = activeCell.getColumn();
var row = activeCell.getRow();
if (e.range.getSheet().getSheetName() == 'Order Sheet') {
if (col == 6) { // assuming status is in column 6 (E), adapt if needed
if (col == 6 && sheet.getRange(row, col + 1).isBlank())
sheet.getRange(row, col + 1).setValue(new Date()).setNumberFormat('DDD, dd MMM'); // change the display format to your preference here
}
if (col == 6 && sheet.getRange(row, col).isBlank())
sheet.getRange(row, col + 1).setValue("")
}
}
Now I have a new sheet, "Work Hours" where I want to utilize the same sort of functionality (different column and time instead of date), but even when I copy this script to a new script file (Project "Work Hours code", file name "Code.gs") and change the SheetName (line 7) to 'Work Hours' it doesn't seem to work.
I thought maybe it was because I had 2 projects with the Code.gs file, but changing that to Code2.gs didn't make a difference (changed it back, just in case).
Also, eventually I want this to run even when the sheet is closed, because I need it to record when data comes in from an external source. Is that possible? I presume I'd have the change the variable for "sheet" since it wouldn't be active?