Script Editor in Google Sheets: What It Is & How to Use It
In this article
The Script Editor in Google Sheets is a built-in coding environment that lets you write custom functions, automate repetitive tasks, and extend Sheets using Google Apps Script (a JavaScript-based language). You open it from the menu: Extensions > Apps Script. Once there, you can create macros, add custom menus, send emails, or connect to external APIs—all without leaving your browser.
What Is Google Apps Script?
Google Apps Script is the scripting platform that powers the Script Editor. It runs on Google’s cloud servers and can interact with Google Workspace apps (Sheets, Docs, Gmail, Calendar) as well as external services. It’s free for personal use and included with Google Workspace accounts. The language is a subset of JavaScript (ES3 with some modern features), so if you know basic JavaScript, you can start writing scripts quickly.
When you open the Script Editor from a spreadsheet, it creates a new project tied to that spreadsheet. The project contains one or more .gs files (Google Script files) where you write your code. You can also add HTML files for custom dialogs or sidebars.
How to Open the Script Editor
Opening the Script Editor is straightforward:
- Open your Google Sheet in a web browser.
- Click Extensions in the top menu.
- Select Apps Script from the dropdown.
- A new tab opens with the script editor. It starts with a blank
function myFunction() {}.
You can also open it from the Macro menu if you’ve already recorded a macro—recorded macros are stored as Apps Script functions.
What Can You Do with the Script Editor?
The Script Editor is powerful because it can automate almost anything you do manually. Common uses include:
- Custom functions – Create your own formulas like
=MYFUNC(A1)that perform calculations not available in built-in functions. - Automated reports – Send a PDF of a sheet via email on a schedule.
- Data cleaning – Remove duplicates, format cells, or validate entries across many rows.
- Menus and buttons – Add a custom menu item like “Generate Invoice” that runs a script.
- Triggers – Run code on open, on edit, or on a time-driven schedule (e.g., every hour).
- Integration with APIs – Fetch data from external services like weather, stock prices, or internal databases.
Writing Your First Script: A Simple Example
Suppose you want a custom function that adds two numbers and multiplies by 10. In the script editor, replace the default code with:
function TIMES10(a, b) {
return (a + b) * 10;
}
Save the project (Ctrl+S / Cmd+S), then go back to your sheet. In any cell, type =TIMES10(2, 3) and press Enter. The cell will return 50. Custom functions appear in the function list when you type = after you save and refresh.
Note: Custom functions cannot change other cells—they only return a value. For actions that modify the sheet (like setting values), you need to run a script from the menu, a button, or a trigger.
Using Triggers to Automate Tasks
Triggers let your scripts run automatically. To set one up:
- In the Script Editor, click the clock icon (Triggers) on the left.
- Click + Add Trigger.
- Choose the function to run (e.g.,
sendReport). - Select the event source (Time-driven, From spreadsheet) and the type (on open, on edit, or a specific time interval).
For example, to email a summary every morning at 8 AM, you’d write a function that builds the email and then set a time-driven trigger. Triggers require authorization—you’ll see a permission prompt the first time.
Common Problems and How to Avoid Them
New users often hit a few predictable issues:
- Authorization errors – When you run a script that accesses your data, Google asks for permission. Always review the scopes and click “Allow”. If you see “This app isn’t verified”, you can still proceed under “Advanced” for personal scripts.
- Quota limits – Apps Script has daily quotas (e.g., 20,000 URL fetch calls, 90 minutes of trigger runtime). For heavy use, check the current quotas in the Apps Script documentation.
- Debugging – Use
Logger.log()to print values to the Log (View > Logs) or useconsole.log()and view the Stackdriver logs. The debugger lets you set breakpoints. - Case sensitivity – JavaScript is case-sensitive.
getRangeis not the same asgetrange. - Mac differences – The Script Editor works the same in a browser on Mac, but keyboard shortcuts differ: Cmd+S to save, Cmd+R to run (instead of Ctrl+S / Ctrl+R).
Script Editor vs. Macros vs. Add-ons
You have three ways to automate Sheets, and it’s useful to know which fits:
- Macros – Record your actions (Extensions > Macros > Record macro). They generate Apps Script code automatically. Great for simple, repetitive formatting or data entry tasks, but limited to what you can do manually.
- Script Editor – Full control. You can write complex logic, use loops, conditionals, and integrate with other services. Best for anything beyond basic recording.
- Add-ons – Pre-built tools (like “Advanced Find & Replace” or “Yet Another Mail Merge”) that you install from the Google Workspace Marketplace. They’re scripts written by third parties; you can also publish your own script as an add-on.
Costs and Safety
The Script Editor itself is free. You’re only charged if you use paid Google Cloud services (like a premium API) or if you exceed the generous free quotas (which is rare for personal use). For Google Workspace business accounts, Apps Script is included.
Safety considerations:
- Scripts can read and modify your spreadsheet, send emails, and access other Google services. Only run scripts you trust, and review the permissions they request.
- Before running a script that modifies data, make a copy of your spreadsheet (File > Make a copy). There’s no Ctrl+Z for script changes that affect many cells.
- If you share a spreadsheet, anyone with edit access can open the Script Editor and view or modify the script. Be careful with sensitive code or credentials—store secrets in Script Properties, not hard-coded.
- Apps Script runs on Google’s servers, so your data is processed in the cloud. For sensitive data, check your organization’s policy.
Frequently Asked Questions
Can I use the Script Editor to create a custom function that updates other cells?
No. Custom functions (like =MYFUNC()) can only return a value to the cell they’re called in. They cannot modify other cells, menus, or triggers. To change other cells, you need to run a script from a menu, button, or trigger—not as a custom function.
How do I run a script manually?
In the Script Editor, select the function from the dropdown at the top and click the Run button (▶). Or, in the spreadsheet, you can create a custom menu that calls the function. For example, add this to your script:
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Custom Menu')
.addItem('My Function', 'myFunction')
.addToUi();
}
Reload the sheet, and you’ll see a new “Custom Menu” menu.
Why is my script not running or showing an error?
Check the Log (View > Logs) or Execution Transcript for error messages. Common causes: missing permissions (authorize the script), incorrect function names, or syntax errors. Use the debugger (line numbers on the left) to step through your code. Also ensure you’ve saved your script before running.
Can I use the Script Editor offline?
No. The Script Editor is a web-based IDE, so you need an internet connection to edit and run scripts. However, you can write code in any text editor and paste it into the Script Editor later.
Is Apps Script the same as JavaScript?
Apps Script is based on JavaScript but has its own built-in services (like SpreadsheetApp). It supports most modern JavaScript features (in V8 runtime) like arrow functions and template literals, but some browser APIs (like DOM) are not available. It’s designed for server-side automation, not web pages.
How do I delete a script project?
In the Script Editor, go to the project settings (gear icon) and scroll to “Delete project”. This permanently removes the script and any triggers. The spreadsheet itself is unaffected. Alternatively, you can just remove all code and save—it will still exist but do nothing.