I'm trying to do 2 things in a spreadsheet each time a cell in col8 is selected. 1st increase the value of the cell in col7 and set a timestamp in the first blank cell in the row. I'm stuck on the timestamp. Increasing the value works and I can set the timestamp to a specific cell as show in the code or in the last col of the sheet, but I can't find a solution to set it in the first blank cell of the row.
function onSelectionChange(e) {
const as = e.source.getActiveSheet();
const col = e.range.getColumn();
const row = e.range.getRow();
if (as.getName() == 'Sheet1' && col == 8){
const range = as.getRange(row,7);
range.setValue(range.getValue()+1);
e.range.setValue('Present');
}
onEdit(e);
}
function onEdit(e) {
var attendanceSheet = e.source.getActiveSheet();
var row = e.range.getRow();
var col = e.range.getColumn();
if(attendanceSheet.getName() == 'Sheet1' && col == 8) {
if (attendanceSheet.getRange(row, 12).getValue() === '')
attendanceSheet.getRange(row, 12).setValue(new Date());
}
}