To add Apps Script to a Google Sheet, open the spreadsheet in a web browser and choose Extensions > Apps Script. The script editor opens in a new tab; write or paste your code, save it, then run a function to make it work with the sheet.
What Apps Script adds to Google Sheets
Google Apps Script is Google’s cloud-based scripting platform, built on JavaScript. A script can read and change spreadsheet data, apply formatting, create menus or dialogs, and connect Sheets with other Google services. For example, a short script could put a status in a cell, while a larger project might prepare a report and email it to a team.
When you open Apps Script from a spreadsheet, Google creates a project associated with that file. This is called a container-bound script. The association is useful because the code can work with the spreadsheet it belongs to without needing you to find and enter its file ID. The script is still a separate project: adding it does not put code into a cell or turn it into a spreadsheet formula.
Apps Script is optional. You can use Sheets normally without creating a project, and you do not need to install a separate desktop program. The editor and script run online, subject to your Google account’s access and Google’s service limits.
Open the script editor and create a project
- Open the Google Sheets file in a browser and make sure you have permission to edit it.
- Choose Extensions > Apps Script from the Sheets menu.
- Wait for the Apps Script editor to open. A new project usually contains a file named
Code.gswith a starter function. - Replace or edit the starter code, then save the project using the editor’s save control.
- Choose the function you want to run from the function selector in the editor and select Run.
If the menu item is missing or unavailable, confirm that you are in Google Sheets in a browser and can edit the file. An organization’s administrator may also restrict Apps Script. If you opened an Excel file in compatibility mode rather than converting it to Google Sheets, save or convert it to Google Sheets before relying on Apps Script features.
Run a small first script
A good first project makes one obvious change that is easy to check. For example, this function writes a note to cell B1 on the active sheet:
function writeRunNote() {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
sheet.getRange('B1').setValue('Updated by Apps Script');
}
Save the code, select writeRunNote in the function selector, and click Run. Return to the spreadsheet and check B1. If it already contains something important, choose a different cell in the code before running the example; the function replaces the cell’s existing value.
The example uses the Apps Script service called SpreadsheetApp. getActiveSpreadsheet() refers to the spreadsheet associated with the project when it is run in this context, getActiveSheet() selects the active tab, and getRange() identifies a cell. setValue() writes the text. These methods are not spreadsheet formulas; they are instructions executed by the script.
Authorize the script and understand permissions
The first time you run code that needs access to Google data, Google may ask you to authorize it. Review the permissions screen and make sure the requested access makes sense for the code and the task. Authorization allows the script to act with the permissions granted to the account running it; it does not make the script safe simply because it is attached to a familiar spreadsheet.
If you wrote the code yourself, inspect it before granting access. If someone else supplied it, ask what services it uses and why. Be especially cautious about code that sends email, reads files, contacts external websites, or asks for broader account access than the task appears to need. A warning that an app is not verified can appear for projects that have not gone through Google’s verification process; do not treat that warning as proof of safety. Only proceed when you trust the project and understand the requested permissions.
Scripts can fail authorization if the account lacks access to a spreadsheet or connected service. In a work or school account, administrator policies may block certain services or unverified apps. Ask the administrator about the restriction rather than trying to bypass it.
Useful things a sheet-bound script can do
Simple scripts are valuable when a task is repetitive, precise, and difficult to handle with built-in spreadsheet features alone. Common examples include:
- Adding a custom menu, such as a “Prepare report” command, when the spreadsheet opens.
- Applying a consistent set of formats to a selected range or newly added data.
- Copying completed rows to an archive tab after a user chooses to run the action.
- Creating a timestamp or status entry when a workflow step is completed.
- Reading spreadsheet values and preparing a summary in another Google service, subject to authorization and service limits.
Apps Script can also create custom functions that are entered in cells, but those functions have restrictions and are not interchangeable with ordinary JavaScript programs. They are generally best for returning a calculated value, not for changing unrelated cells or carrying out actions that require user authorization. For calculations, compare a custom function with built-in Sheets functions first; built-in functions are often simpler to maintain.
Automate a script with menus and triggers
Clicking Run in the editor is useful while developing, but a finished workflow may need a more convenient starting point. A bound script can add a custom menu to Sheets with an onOpen function. When a user opens the spreadsheet, the function can create a menu item that runs another function. This keeps the action available inside the sheet without requiring users to open the code editor.
Triggers can run code in response to events or on a schedule. A simple trigger, such as onOpen or onEdit, follows restrictions intended to keep automatic actions limited. An installable trigger is created through the Apps Script interface and can use additional authorized services. Time-driven triggers can run at intervals, but they do not promise an exact-to-the-minute execution time.
Installable triggers run under the account of the person who created them. That matters when a team shares a spreadsheet: a trigger may have access to services or files through its creator that other editors do not. If the creator loses access or leaves the organization, the automation may need to be reviewed and recreated. Document who owns important triggers and what they do.
Bound scripts, standalone projects, and add-ons
A bound script is attached to one spreadsheet and is usually the simplest choice for automating that file. A standalone Apps Script project is created separately and can be designed to work with one or more spreadsheets. A standalone project may be useful for a central process that manages several files, but it requires deliberately locating or opening the target files and managing access appropriately.
An add-on is different from a one-off script. Add-ons package functionality for use across Google Workspace files and may be installed or distributed to users. If you only need a button or workflow in one spreadsheet, a bound script is typically more direct. If you want a reusable product for many users, consider the extra work involved in distribution, permissions, support, and any applicable Google review requirements.
Excel macros are not the same as Apps Script. Apps Script uses JavaScript and runs in Google’s environment; Excel’s VBA macros run in Excel and use VBA. Code written for one platform does not automatically run in the other. If a file must work in both Sheets and Excel, plan for separate automation or use a cross-platform approach that suits the organization’s tools.
Sharing, safety, and practical limits
Because a bound script belongs to a spreadsheet, people with permission to edit the spreadsheet can generally access and modify its bound script. Do not assume that hiding a tab or protecting a range makes code secret. Avoid placing passwords, private tokens, or sensitive information directly in code that other spreadsheet editors can inspect. Also consider what the script might do if a collaborator changes its code and another user runs it.
Apps Script has quotas and service-specific limits, and those limits can vary by account type and can change. A script that works on a small sheet may run too slowly or exceed a limit when processing thousands of rows one cell at a time. For larger jobs, scripts are often designed to read a range into memory, process the values, and write results back in batches. Check current Apps Script quotas and service documentation before depending on automation for a high-volume or time-critical workflow.
Creating a basic script does not typically require a separate purchase, but access to Google Workspace services, administrator policies, and usage limits can depend on the account and organization. Treat “free” as distinct from unlimited: execution quotas still apply, and a company may control which scripts users can run.
Common problems and how to fix them
- The script runs but changes the wrong tab:
getActiveSheet()uses the active tab. If the code must always target a specific tab, identify that tab explicitly and handle the case where it is missing. - A cell’s old content disappears:
setValue()replaces the value in the target cell. Test with a blank or disposable cell, or adjust the range before running. - Google asks for permission again: A change to the services used by a script can require additional authorization. Review the new request before accepting it.
- The script cannot find a function: Check the function selector, spelling, and whether the code saved successfully. A syntax error elsewhere in the project can prevent a function from running.
- An automatic action does not happen: Confirm that the correct trigger exists, that it belongs to an account with necessary access, and that the function can run under trigger restrictions. Check the Apps Script execution history for errors.
- A script fails on a large data set: Reduce repeated calls to Sheets services, process data in batches, and check the relevant execution and service quotas.
For debugging, use the editor’s execution details and logs, and test changes on a copy of the spreadsheet when the script can overwrite or delete data. A script’s actions may not be reversible with the spreadsheet’s normal undo history, so a backup is a sensible safeguard before running unfamiliar or destructive code.
Frequently Asked Questions
Can I add Apps Script to any Google Sheet?
In general, an editable Google Sheets file can have a bound Apps Script project. However, your account or organization may restrict script access, and a file that is still an Excel workbook may need to be converted to Google Sheets first.
Do I need to install Apps Script?
No separate desktop installation is needed. Open the spreadsheet in a browser and use Extensions > Apps Script to open the online editor. The editor and script execution require an internet connection.
Can other people see the script in my spreadsheet?
People who can edit a spreadsheet can generally access its bound script project. Do not store secrets in code or rely on the script to hide information from spreadsheet editors. Review sharing permissions before adding sensitive automation.
Can Apps Script run automatically when a cell changes?
Yes, an edit trigger can respond to changes, but simple triggers have limitations. For actions that need additional permissions, an installable trigger may be appropriate. Test the behavior and account ownership before relying on it for a shared workflow.
Is Apps Script the same as a Google Sheets add-on?
No. A script can automate a particular spreadsheet, while an add-on is packaged for use across files or by multiple users. Start with a bound script for a small, file-specific task; consider an add-on when the functionality needs broader distribution.
Related
- Insert Outlook Email Into Excel: Methods That Work
- How to Copy Excel Cells to Word Without Losing Format
- Copy a Word Document into Excel: Best Methods and Tips
Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.
More in How-to basics
- How to Delete a Header from One Page in WordTo delete a header from just one page in Word, isolate that page in its own section, turn…
- How to Insert a Checkbox in Microsoft Word: Two WaysTo insert a checkbox in Microsoft Word, use Developer > Check Box Content Control for a box readers…
- Google Sheets: Count Cells by Highlight ColorGoogle Sheets does not have a built-in COUNTIF function that counts cells just because they are highlighted with…
- How to Delete a Blank Page in Word Without Losing TextTo delete a blank page in Word, turn on formatting marks with Ctrl+Shift+8 on Windows or Command+8 on…
- Create an Outlook Signature: Steps for Every VersionTo create an Outlook signature, open the signature settings for your version of Outlook, make a signature, and…
- Google Sheets COUNTIF by Color: Practical Ways to CountGoogle Sheets’ COUNTIF cannot count cells by fill color directly: it evaluates cell values against a criterion, not…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.