How would I edit this script to only return odd columns in the range?
function onEdit() {
var s = SpreadsheetApp.getActiveSheet(); if (s.getName() == "2025 Attendance") {
var r = s.getActiveCell(); if (r.getColumn() >= 3 && r.getColumn() <= 20) {
var nextCell = r.offset(0, 1); if (nextCell.getValue() === '') //checks whether the adjacent cell is empty or not
nextCell.setValue(new Date());
}
}
}
I’ve tried changing the range but I can’t figure out how to set the range to only odd numbers.
2
Answers
Affect only odd-numbered column
You can try this modified version of your code:
Code
I added
r.getColumn() % 2 !== 0
which effectively checks if the column being edited is an odd-numbered column and adds it to your other conditions.Sample Output
References: