I’m working on a Google Sheets project and need some help. I want to add date stamps to certain rows when they’re edited, but not to others. My current script works fine, but it adds dates to all rows including headers.
Here’s what I’m trying to do:
Add date stamps only to rows 9-13, 15-18, and 20-26
Keep header rows (and others) without date stamps
Update the date in column C when any cell in that row is edited
My current script looks like this:
function updateDateOnEdit() {
let sheet = SpreadsheetApp.getActiveSheet();
let editedCell = sheet.getActiveCell();
let editedRow = editedCell.getRow();
if (editedCell.getColumn() !== 3) {
let today = new Date();
let formattedDate = Utilities.formatDate(today, 'GMT-07:00', 'MM/dd/yy');
sheet.getRange('C' + editedRow).setValue(formattedDate);
}
}
How can I modify this to work only on the specific rows I mentioned? Any help would be great!
Having worked extensively with Google Sheets, I can offer some insights on your date stamping issue. Your approach is on the right track, but you’ll need to modify the script to target specific row ranges.
I’d suggest creating an array of row ranges you want to date stamp, then use a function to check if the edited row falls within these ranges. Something like this:
Then, in your main function, use this check before applying the date stamp:
function updateDateOnEdit(e) {
let sheet = e.source.getActiveSheet();
let editedCell = e.range;
let editedRow = editedCell.getRow();
if (isTargetRow(editedRow) && editedCell.getColumn() !== 3) {
let today = new Date();
let formattedDate = Utilities.formatDate(today, Session.getScriptTimeZone(), 'MM/dd/yy');
sheet.getRange(editedRow, 3).setValue(formattedDate);
}
}
This approach ensures date stamps are only added to your specified rows, solving your initial problem efficiently.