Stamp the time when a row is edited
Apps Script recipes › Triggers and long jobs
An onEdit function writes the time into an "Updated" column whenever someone edits that row.
File Code.gs
function onEdit(e) {
const sheet = e.range.getSheet();
if (sheet.getName() !== 'Items' || e.range.getRow() < 2) return;
const header = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0];
const col = header.indexOf('Updated') + 1;
if (!col || e.range.getColumn() === col) return;
sheet.getRange(e.range.getRow(), col, e.range.getNumRows(), 1).setValue(new Date());
}
Good to know
- onEdit works only in a script that lives in the spreadsheet. It doesn't fire for changes made by code or by a form.
- A simple trigger can't send email or open other files; use an installable trigger for that.
Let the AI put it in your appGAS AI Builder knows every recipe here. Describe your app and it uses this code where it fits, in a Google Apps Script project in your own Drive.
Use it in a project