GuidesGoogle Sheets

How to use Apps Script in Google Sheets

Learn how to open, write, and run Apps Script in Google Sheets to automate tasks, build custom functions, and add menus.

Quick answer

Open a Google Sheet, click Extensions, then Apps Script to launch the script editor in a new tab. Write JavaScript-based code using the SpreadsheetApp class to read, write, or format cells. Save the project, click Run to authorize permissions, then check your sheet or the execution log for results.

Steps at a glance

  1. Open your spreadsheet and click Extensions, then Apps Script
  2. Delete the placeholder code in the editor window
  3. Write a function using SpreadsheetApp to interact with cells
  4. Click the disk icon to save and name your project
  5. Click Run and grant the requested permissions
  6. Check your sheet or the Execution log for output
  7. Reload the spreadsheet to see any custom menus you added

Summary

Apps Script is a built-in scripting tool in Google Sheets that lets you write JavaScript-based code to automate repetitive tasks, build custom functions, and connect your spreadsheet to other Google services. It runs directly from your browser with no separate software to install, making it accessible even on a free Google account.

Step-by-step guide

  1. Step 1

    Open the Apps Script editor

    Open your Google Sheet, click Extensions in the top menu, then select Apps Script. A new browser tab opens with the Apps Script editor, already linked to your current spreadsheet so any code you write can read and modify it directly.

  2. Step 2

    Clear the placeholder code

    The editor opens a file called Code.gs with an empty myFunction() template. Delete this placeholder text so you have a clean space to write your own function, or keep the structure if you plan to build on it.

  3. Step 3

    Write a simple function

    Use the SpreadsheetApp class to interact with your data. For example, a function that gets the active sheet and writes a value into cell A1 might read: function addValue() { SpreadsheetApp.getActiveSheet().getRange('A1').setValue('Hello'); }. Most Sheets scripts work by looping through arrays of rows and columns.

  4. Step 4

    Save and name your project

    Click the disk icon or press Ctrl+S (Cmd+S on Mac) to save. Enter a descriptive project name, like 'Weekly Formatting Script,' so you can find it again if you build multiple scripts for the same spreadsheet.

  5. Step 5

    Run the script and authorize access

    Click Run at the top of the editor. The first time you run a script, Google asks you to review and authorize the permissions it needs, such as viewing and editing your spreadsheets. Click Allow after reviewing the request to let the script execute.

  6. Step 6

    Check the results

    Switch back to your spreadsheet tab to see the changes the script made, or return to the Apps Script editor and open the Execution log to review output, errors, or debugging messages. If nothing changed, check the log for a clear error description.

  7. Step 7

    Add a custom menu (optional)

    To make a script reusable for others, add an onOpen() function that creates a custom menu item in your spreadsheet's toolbar. This is especially useful if you plan to share edit access with teammates who need to trigger the script without touching code.

Why this matters

You need this when a spreadsheet task is too repetitive or complex for standard formulas — like formatting hundreds of rows on a schedule, sending automated emails from data, or building a custom menu for teammates. Learning Apps Script unlocks automation you'd otherwise redo by hand every time.

Frequently asked questions

  • Is Apps Script free to use in Google Sheets?

    Yes, Apps Script is included at no cost with any Google account, including free personal accounts. There are daily quotas on things like email sends or execution time, but these limits are generous for typical personal or small-team use.

  • Do I need coding experience to use Apps Script?

    Basic JavaScript knowledge helps, especially understanding arrays and functions, but you can start with simple recorded macros that generate code automatically. From there, editing existing code is easier than writing a script from scratch.

  • Can I share a script with people I collaborate with?

    Yes. Anyone with edit access to the spreadsheet can also open and run the attached Apps Script project. Review who has edit permissions before adding scripts that modify data automatically.

  • Will running scripts slow down my spreadsheet?

    Well-written scripts run quickly and only execute when triggered, so they won't slow down normal spreadsheet use. Scripts that loop through very large ranges can take longer, so it's best to test on a smaller data set first.

Create interactive demos like this one — free, no coding required.

Start for free →