Auto-Insert Static Timestamp on Row Edit (onEdit Trigger)
Automatically inserts an unchangeable static date and time stamp into Column B whenever a user edits or updates data in Column A.
function onEdit(e) {
const range = e.range;
const sheet = range.getSheet();
// Only execute on 'Tracker' tab and when editing Column 1 (A)
if (sheet.getName() !== 'Tracker' || range.getColumn() !== 1 || range.getRow() === 1) {
return;
}
const timestampCell = sheet.getRange(range.getRow(), 2); // Column B
// If edited cell has content and timestamp is empty, write static date
if (range.getValue() !== '' && timestampCell.getValue() === '') {
timestampCell.setValue(new Date()).setNumberFormat('yyyy-mm-dd hh:mm:ss');
}
}Line-by-Line Code Explanation
Step-by-Step Setup & Deployment
- Create a sheet tab named "Tracker".
- Open Extensions > Apps Script, replace all code with this function, and click Save.
- No manual trigger setup is required; simple onEdit triggers fire automatically.
Best Practices for Quota & Rate Limit Management
When deploying this automation in Google Workspace, adhere to these operational principles:
- Batch Reads & Writes: Never execute
getValue()orsetValue()inside loops. Read ranges into memory in 1 call, process arrays in V8 memory, and commit changes with a singlesetValues()call. - Execution Timeouts: Apps Script terminates scripts exceeding 6 minutes. For multi-thousand row datasets, implement batch pagination with resume timestamps stored in
PropertiesService. - OAuth Permissions: Scope your manifest (
appsscript.json) narrowly to prevent security prompts from alarming external team members.
Frequently Asked Questions
Is Google Apps Script completely free to use?
Yes. Google Apps Script is built into all free Google accounts and Google Workspace editions. There are no server fees or subscription costs for running scripts within daily quotas.
Can I run this script on an automated schedule without keeping my computer on?
Yes. Time-driven triggers execute on Google's cloud infrastructure. Your script will run reliably even when your computer is closed or offline.
More Google Sheets Automation Snippets
Generate PDF from Google Sheet & Email as Attachment
Converts a specific sheet tab or printable invoice range into a styled PDF blob and emails it to a client or manager with custom HTML formatting.
Google SheetsAuto-Move Completed Rows from Active Sheet to Archive Tab
When a task or lead status is marked "Done" or "Closed", this script cuts the entire row from the active working tab and appends it to an "Archive" tab.
Google SheetsBulk Website HTTP Status Code Checker in Google Sheets
Loops through hundreds of URLs listed in Column A, performs lightweight HEAD/GET HTTP requests, and writes HTTP status codes (200, 301, 404, 500) into Column B.