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
Open Extensions > Apps Script and create a function named onEdit or bind onEdit(e) in the script.
-
2
The event object e includes range, value, oldValue, and source so your code knows what changed.
-
3
Save the script and edit a cell in the sheet to test. Simple onEdit runs for any edit in the file.
-
4
For stricter control, use an installable onEdit trigger from the Triggers page in Apps Script.
-
5
{:"Keep the handler fast"=>"read e.range, branch on sheet name or column, then update only what you need."}
-
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().
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
Spreadsheet Automation 101 Lesson 2: onEdit() Trigger
Automate Google Sheets With Zero Experience
What Can You Automate in Google Sheets? Every single trigger available to Google Sheet users
Uncheck Every Checkbox in Google Sheets
Wrap Your Mind Around This - Learn to Code in Google Sheets Part 6
Creating a Live Message in Google Sheets
Related blog posts
Guides that explain onEdit trigger in more depth.
What Can You Automate in Google Sheets? Every single trigger available to Google Sheet users
Make your data tasks simpler & efficient. Discover the power of automation in Google Sheets with a comprehensive guide that covers everything from triggers to scripts.
Read post →How to reference a different Google Spreadsheet in Apps Script?
Transferring Data Between Cells in Different Spreadsheets
Read post →Explore Coding in Google Sheets
Did you know you can actually code in Google Sheets?
Read post →Related terms
Apps Script triggers
Triggers tell Apps Script when to run a function: on edit, on open, on a schedule, or when a form is submitted. Simple triggers use reserved names like onEdit. Installable triggers are created in the Apps Script Triggers page and can do more, including running as a specific user or on a timer.
Read guide →Script Editor
The Script Editor is the Apps Script workspace inside your spreadsheet where you write JavaScript that talks to Sheets, Gmail, and other Google services. You open it from Extensions > Apps Script. Every function you save can be run manually, bound to a trigger, or linked from a custom menu.
Read guide →Google Sheets automation
Automation means work happens without repeating the same clicks every day: imports update, emails send, rows move, and dashboards refresh. In Sheets, automation usually stacks built-in features, Apps Script, and sometimes the Sheets API or add-ons. Start with the lightest tool that still solves the job.
Read guide →Google Sheets workflows
A workflow is the path work takes through your sheet: intake, review, approval, done. Good workflows use consistent columns, statuses everyone understands, and just enough automation to move tasks forward without hiding steps from the team.
Read guide →Done reading about onEdit trigger?
Membership unlocks 600+ 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.