Google Sheets AutomationDifficulty: Beginner⚡ Simple onEdit(e) trigger

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.

Required OAuth Scopes: None (Simple Trigger - No Authorization Prompt Required)
Code.gs (Apps Script V8 Runtime)
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

Line 1: Simple trigger function that fires automatically on every user cell change.
Line 5-7: Guard clause checking tab name, column index (1 = A), and ignoring row 1 headers.
Line 9: Targets adjacent Column 2 (B) on the exact row modified.
Line 12-14: Writes the current system Date object with formatting only if timestamp does not exist.

Step-by-Step Setup & Deployment

  1. Create a sheet tab named "Tracker".
  2. Open Extensions > Apps Script, replace all code with this function, and click Save.
  3. 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() or setValue() inside loops. Read ranges into memory in 1 call, process arrays in V8 memory, and commit changes with a single setValues() 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