What is the onEdit trigger in Google Sheets?

The onEdit trigger runs a script automatically when someone changes a cell in your spreadsheet. It is one of the simplest ways to make Sheets react to user input without clicking a custom menu. You define the function in Apps Script and bind it to the onEdit event for that file.

When to use it

Use onEdit when you need instant reactions to edits: stamping a last-updated time, validating input, copying a row to a log tab, or showing a warning when a status changes.

When to skip it

Skip onEdit for heavy work, bulk imports, or anything that must run when nobody is editing. Long-running scripts can slow the sheet or hit execution limits. Use time-based or installable triggers instead.

How it works

  1. 1

    Open Extensions > Apps Script and create a function named onEdit or bind onEdit(e) in the script.

  2. 2

    The event object e includes range, value, oldValue, and source so your code knows what changed.

  3. 3

    Save the script and edit a cell in the sheet to test. Simple onEdit runs for any edit in the file.

  4. 4

    For stricter control, use an installable onEdit trigger from the Triggers page in Apps Script.

  5. 5

    {:"Keep the handler fast"=>"read e.range, branch on sheet name or column, then update only what you need."}

  6. 6

    Add error handling and avoid infinite loops when your script writes back to the same range.

Examples in Google Sheets

Timestamp when a status changes

If column D is "Done", write the current date in column E on the same row. onEdit checks e.range.getColumn() and e.value before setting the timestamp.

Block invalid entries

When someone types in the Amount column, compare the value to a max in a Settings tab. If it is too high, clear the cell and show a Browser.msgBox warning.

Append edits to a log sheet

Copy the edited row to a hidden Log tab with user email and timestamp from Session.getActiveUser().

Build this without starting from a blank cell

Use a Better Sheets tool for onEdit trigger, then watch a walkthrough when you want the full pattern.

Better Sheets resources

Common mistakes

  • Naming the function something other than onEdit without creating an installable trigger, so nothing runs.
  • Doing slow work like external API calls inside onEdit, which frustrates editors and may time out.
  • Writing back to the cell that fired the trigger without checking oldValue, causing endless re-fires.
  • Assuming onEdit runs for formula recalculations only; it fires on direct edits, not every recalc.
  • Forgetting that simple onEdit cannot call services that need authorization until the user approves once.

Frequently asked questions

Does onEdit run when a formula updates?
onEdit runs when a user edits a cell directly. Formula results that change because another cell changed do not always fire onEdit. Use onChange or a time-driven trigger if you need broader coverage.
Can onEdit see which user made the edit?
Simple onEdit runs as the active user. Session.getActiveUser().getEmail() often works for logged-in Google accounts, but may be blank for some anonymous or limited sessions.
What is the difference between onEdit and an installable onEdit trigger?
A function literally named onEdit is a simple trigger with fewer permissions. An installable onEdit trigger is created in the Triggers UI and can run with broader authorization.
Why does my onEdit script not run?
Check the function name, syntax errors in Apps Script, and whether the edit happened in an IMPORTRANGE or protected range your script cannot touch.
Can onEdit run on multiple sheets?
Yes. Use e.source.getActiveSheet().getName() to branch logic per tab in the same spreadsheet file.
Is onEdit the same as On Edit in Zapier or other tools?
The idea is similar (react to a change), but onEdit is built into Google Apps Script inside your file. It does not require a third-party connector.
How do I debug onEdit?
Use Logger.log or console.log in the handler, then View > Executions in Apps Script to read output after you make a test edit.
Can onEdit send email?
It can call MailApp or GmailApp if the user has authorized the script, but heavy mail from every edit is a bad pattern. Debounce or queue notifications instead.

Related Tutorials

Watch how onEdit trigger works

Browse more tutorials
Spreadsheet Automation 101 Lesson 2: onEdit() Trigger

Spreadsheet Automation 101 Lesson 2: onEdit() Trigger

One of the things to learn: We can only have one onEdit() in our entire ...
Automate Google Sheets With Zero Experience

Automate Google Sheets With Zero Experience

By the end of this video you should be knowledgeable about how to automa...
What Can You Automate in Google Sheets? Every single trigger available to Google Sheet users

What Can You Automate in Google Sheets? Every single trigger available to Google Sheet users

Learn about triggers, hourly, daily, weekly, etc.
Uncheck Every Checkbox in Google Sheets

Uncheck Every Checkbox in Google Sheets

Automatically uncheck a whole range of checkboxes. Or just do it yoursel...
Wrap Your Mind Around This - Learn to Code in Google Sheets Part 6

Wrap Your Mind Around This - Learn to Code in Google Sheets Part 6

this completes learn to code in Google Sheets and I wanted to finish off...
Creating a Live Message in Google Sheets

Creating a Live Message in Google Sheets

Sit back and enjoy this comprehensive tutorial on how to create a live m...

Related blog posts

Guides that explain onEdit trigger in more depth.

Browse the blog

Related glossary terms

Done reading about onEdit trigger?

Membership unlocks 636+ tutorials, unlimited generators, and every template. Practical lessons. Zero fluff.

Need this once

Jump to a free tool or a single tutorial for this topic.

Learning Sheets for real

Unlock the full library, generators, and templates with membership.