I'm currently using the below script to timestamp when an edit is made to column 7 on a sheet named "Sheet 1".
function onEdit(e) {
if ([7].indexOf(e.range.columnStart) != -1) {
e.range.offset(0, 7).setValue(new Date()).setNumberFormat("dd.MM.yyyy at HH:mm");
}
}
I have a second sheet "Sheet 2" which I need to run the same script on but against column 5.
function onEdit(e) {
if ([5].indexOf(e.range.columnStart) != -1) {
e.range.offset(0, 7).setValue(new Date()).setNumberFormat("dd.MM.yyyy at HH:mm");
}
}
I've tried .getSheetByName("Sheet1")
but just cant seem to get it working correctly.
Best Answer
Please try the following piece of code.
Code
Explained
The code reads as follows:
I think onEdit functions deserve some extra attention to avoid un-necessary calculations. If you were to include the sheet name, if would check the sheet name every time you change a cell. By restricting that to the columns only, you avoid that.