Recipe
Add a timestamp when a row is edited in Google Sheets
Whenever a cell in columns A to C changes, the current date and time is written to column D of the same row, in the spreadsheet's own time zone.
Set it up
- Open the sheet, then Extensions > Apps Script. Paste the script and save.
- Edit a cell in A, B or C on Sheet1. Column D fills in.
- No trigger setup is needed. Change TS if your columns or tab name differ.
The script
/**
* Stamp the date and time in column D when a cell in A-C changes.
* Simple trigger: runs as soon as it is saved, no setup.
*/
var TS = { sheetName: 'Sheet1', watchFrom: 1, watchTo: 3, stampCol: 4, format: 'yyyy-MM-dd HH:mm' };
function onEdit(e) {
if (!e || !e.range) return 'skip:no-event';
var range = e.range;
var sheet = range.getSheet();
if (sheet.getName() !== TS.sheetName || range.getRow() < 2) return 'skip';
if (range.getColumn() > TS.watchTo || range.getColumn() + range.getNumColumns() - 1 < TS.watchFrom) return 'skip';
var tz = SpreadsheetApp.getActiveSpreadsheet().getSpreadsheetTimeZone();
var stamp = Utilities.formatDate(new Date(), tz, TS.format);
for (var r = 0; r < range.getNumRows(); r++) {
sheet.getRange(range.getRow() + r, TS.stampCol).setValue(stamp);
}
return 'stamped';
}What you should see
| Item | Qty | Note | Edited |
|---|---|---|---|
| Pens | 40 | Reorder | 2026-11-14 09:41 |
| Tape | 12 |
Edit B2 and D2 fills in. Sample values, not output from a real account.
Common errors and fixes
- Nothing happens
- The function must be named exactly onEdit, and TS.sheetName must match the tab.
- The timestamp is in the wrong time zone
- The script reads the spreadsheet time zone. Set it in File > Settings.
- TypeError: Cannot read properties of undefined (reading 'range')
- You ran onEdit from the editor. It only works when a cell edit fires it.
Permissions. Running this script asks you to grant Google permissions for the services listed above, to your own script. TriggerShelf never receives your Google data. See the permissions table. Google will show "Google hasn't verified this app"; that is expected for a script you paste yourself.
TriggerShelf is independent and not affiliated with or endorsed by Google LLC. Google Sheets, Gmail, Google Drive and Apps Script are trademarks of Google LLC. Quota figures come from Google's Apps Script quotas page. Test on a copy first.