I have started using this script to auto populate the date when data is entered into the column next to it for Google Sheets. It needs to do this on multiple columns as new data is entered. This script works on all of the columns but the last paired: 13-14 and 15-16. It was working before but now it has stopped. Any help with what I need to do? I'm not versed in code and I learned this much from YouTube! Thanks!
function onEdit(e) {
var row = e.range.getRow();
var col = e.range.getColumn();
if(col == 5 && row > 1 && e.source.getActiveSheet().getName() === "IRLA Level" ) {
e.source.getActiveSheet().getRange(row,6).setValue(new Date())
if(col == 7 && row > 1 && e.source.getActiveSheet().getName() === "IRLA Level" )
e.source.getActiveSheet().getRange(row,8).setValue(new Date())
if(col == 9 && row > 1 && e.source.getActiveSheet().getName() === "IRLA Level" )
e.source.getActiveSheet().getRange(row,10).setValue(new Date())
if(col == 11 && row > 1 && e.source.getActiveSheet().getName() === "IRLA Level" )
e.source.getActiveSheet().getRange(row,12).setValue(new Date())
if(col == 13 && row > 1 && e.source.getActiveSheet().getName() === "IRLA Level" )
e.source.getActiveSheet().getRange(row,14).setValue(new Date())
if(col == 15 && row > 1 && e.source.getActiveSheet().getName() === "IRLA Level" )
e.source.getActiveSheet().getRange(row,16).setValue(new Date())
}
}
CodePudding user response:
Try it this way
function onEdit(e) {
const sh = e.range.getSheet();
const idx = [5,7,9,11,13,15].indexOf(e.range.columnStart);
if(sh.getName() == "IRLA Level" && e.range.rowStart > 1 && ~idx) {
e.range.offset(0,1).setValue(new Date());
}
}