Apps Script: Triggers, Macros & Automation

Master Google Sheets Automation

Google Apps Script is a powerful automation platform for Google Sheets. Learn how to use triggers like onEdit and onOpen to automate workflows, create custom menus, build web apps, and manage bound scripts in the script editor. Understand simple triggers vs install triggers, monitor your code with execution logs, configure manifest files, manage scope permissions, and stay within quota limits.

Key Apps Script Concepts

Triggers & Automation

  • Simple trigger: Functions like onEdit and onOpen that run automatically
  • Install trigger: Runs once when a user installs your script
  • Create custom menus for user interactions
  • Monitor scripts with execution log

Script Types & Configuration

  • Bound script: Attached directly to a Google Sheet
  • Use the script editor to write and debug code
  • Deploy web apps for external access
  • Configure manifest for advanced features
  • Manage scope permissions and quota limits

Featured Code Snippets

Make Spreadsheet Private

Useful to use this script if you want to privatize your sheet at some specific time

When Urgent, Move to Top of Google Sheet

This Google Apps Script function, onEdit(e), automatically moves rows to the top of "Sheet1" when a specific condition is met. Here's how it works: It detects when a user edits a cell in the sheet. If the edited cell is in column 3 (C), the row is greater than 1, the new value is "Urgent", and the sheet name is "Sheet1", the function triggers. It extracts the row's data from columns A to E. A new row is inserted at the second row (just below the headers). The extracted data is copied into this new row. The original row is deleted, ensuring that urgent tasks always appear at the top. This script is useful for prioritizing urgent tasks dynamically in a Google Sheet.

Custom Menu - 1 Function

One menu function

Dall-e-3 API Call

Create an image from Google Sheets with OpenAI's Dall-e

Duplicate Template

Create a copy of the template. You can trigger this every day or every month, or every week.

Create Tab For Every Day of the Year

Creates a new tab for every day of the year.

Get month as full month name

This apps script gives you just the full name of the current month, without the day, year, or time. For example instead of Jan. it will be January. The code does the following: new Date(): This creates a new Date object representing the current date and time. .toLocaleString('default', {...}): The toLocaleString method formats the date based on the provided options and the user's local time settings. The 'default' here refers to the system's locale (language and region settings). You can replace it with a specific locale if needed (e.g., 'en-US' for US English or 'fr-FR' for French). { month: 'long' }: This option tells toLocaleString to return only the month in its "long" form. The "long" form means that the full name of the month will be used (e.g., "January" instead of "Jan.").

Email form entries when form filled out

Create a simple html table email and send it automatically when a form is filled out.

Get Sheet ID and Tab GID Into Your Google Sheet

The function retrieves and writes the active spreadsheet ID and the specific sheet ID of "Sheet1" into cells A1 and A2 of "Sheet1", respectively. This can be useful for referencing or logging purposes. Retrieve the Spreadsheet ID: The script retrieves the ID of the active spreadsheet using SpreadsheetApp.getActiveSpreadsheet().getId(). This ID uniquely identifies the spreadsheet. Write the Spreadsheet ID to Cell A1: The script accesses the sheet named "Sheet1" and sets the value of cell A1 to the retrieved spreadsheet ID. Retrieve the Sheet ID of "Sheet1": The script retrieves the ID of the sheet named "Sheet1" using SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1").getSheetId(). This ID uniquely identifies the sheet within the spreadsheet. Write the Sheet ID to Cell A2: The script sets the value of cell A2 in "Sheet1" to the retrieved sheet ID.

Remove Second Row

A Google Apps Script function that deletes the second row of a specific sheet named "Sheet1" in a Google Spreadsheet. Use Cases: Removing Placeholder Data: If the second row contains placeholder or example data that is no longer needed once the spreadsheet is populated with real data, this function can be used to remove it. Deleting Headers: If a new set of headers is to be inserted and the old headers in the second row need to be removed, this function can delete the old header row. Clearing Outdated Information: In scenarios where the second row contains outdated information that is no longer relevant, such as old dates or obsolete entries, this function can be used to clear it. Maintaining Formatting: If the second row is used temporarily to apply or test formatting styles, this function can remove it once the formatting tasks are complete. Workflow Automation: As part of an automated workflow, this function might be used to clean up a sheet at a specific step, ensuring that any temporary or intermediary data in the second row is removed. User Input Cleanup: In cases where users enter data into the second row for initial processing or validation, this function can delete that row after the data has been processed and moved elsewhere. Resetting Templates: If the spreadsheet serves as a template that gets reused, this function can delete any existing data in the second row to reset the template for new input. Error Correction: If there is an error or a mistake in the second row, such as an incorrect entry or a duplicated row, this function can remove the erroneous row to correct the data.

Become an Apps Script Pro: Explore Our Courses

Unlock the power of Google Apps Script with step-by-step, example-driven courses. All courses are included in the Better Sheets Membership, or available as a bundled masterclass on Udemy: Master Spreadsheet Automation .

Learn to Code: Google Apps Script

Start from zero! Learn the basics of coding with real-life Google Sheets problems. Master triggers like onEdit and onOpen, create custom menus, and work with bound scripts in the script editor.

  • No coding experience required
  • Step-by-step video walkthroughs
  • Learn simple triggers and install triggers
  • Monitor code with execution logs
  • Includes a collection of ready-to-copy scripts

Spreadsheet Automation 101

Essential Automation

Dive deep into automating your workflows. Ideal for freelancers, analysts, and business owners seeking to save hours and build robust automated sheets.

  • Trigger scripts on edit, with buttons, or on a schedule
  • Connect and automate Gmail, Slack, and more
  • Create custom menus & UI in Sheets
  • Downloadable templates and scripts
Outcome:

By the end, you’ll be able to automate end-to-end processes in your own business using Apps Script—backed by code samples, templates, and real project walkthroughs.

Advanced Apps Script & More

Deep Dives

Take your skills to the next level with courses on:

  • Building Add-ons for Google Sheets
  • API Integrations & Webhooks with Apps Script
  • Best Practices & Promoting Your Scripts
  • Security and Collaboration Tips
Outcome:

Ideal for anyone ready to publish tools, create complex automations, or lead a team in collaborative script development.

All Courses + More with Better Sheets Membership

Unlock every Apps Script and Google Sheets course, hundreds of copyable code snippets, project templates, and walkthrough videos. Get immediate access to interactive examples and community Q&A. All included in your Better Sheets monthly membership.

Join Better Sheets Membership
Prefer learning on Udemy? Get the bundled masterclass here.
Step-by-Step Guidance

Every course breaks tough topics into simple lessons. Follow along directly inside your own Google Sheets.

Real Projects & Resources

Download all code, sample spreadsheets, and ready-to-use templates for your own projects.

From Beginner to Advanced

Whether just starting or building add-ons, you’ll always find courses, tools, and solutions for your level and goals.

Top YouTube Videos & Playlists for Google Apps Script

Level up faster with hand-picked video tutorials and deep dives—free on YouTube or unlock even more in the Better Sheets members area.

Spreadsheet Automation Fundamentals Playlist
Playlist

Spreadsheet Automation Fundamentals

From foundational skills to essential Apps Script concepts, this playlist takes you step-by-step through automating Google Sheets even if you’re brand new.

  • Get hands-on with triggers, custom functions, and real automations.
  • Perfect for beginners & practical for busy professionals.
Watch Playlist on YouTube
AI in 2 Minutes
Quick Guide

AI in 2 Minutes

Instantly use AI in your Google Sheets with Apps Script—no prior coding required. Learn how to connect and automate AI use-cases in a flash.

  • Supercharge sheets with AI in just 2 minutes.
  • Beginner-friendly, great for rapid prototypes.
Watch on YouTube
Google Sheets for Coders
For Programmers

Google Sheets for Coders

Dive deep into Apps Script for developers and power users. Explore advanced patterns, sheet coding tips, and “dev-mode” productivity boosters.

  • Write scalable, maintainable code in Sheets.
  • Explore APIs, linting, and pro code workflows.
Watch on YouTube
Create a REST API in Sheets
Advanced Project

Build a REST API in Google Sheets

Take spreadsheet automation to the backend: build, deploy, and secure a REST API entirely within Google Sheets using Apps Script.

  • Real coding example: Endpoints, authentication, and use cases.
  • Great for SaaS prototypes & internal tooling.
Watch on YouTube

Want More In-Depth Tutorials?

Unlock exclusive step-by-step Apps Script projects, coding Q&A, and full video courses in the Better Sheets Members Area.

Explore Membership

Apps Script Glossary: Key Terms Explained

Triggers

Simple Trigger
Functions like onEdit and onOpen that run automatically when specific events occur in your Google Sheet.
Install Trigger
Runs once when a user installs your script, perfect for initial setup tasks.
onEdit Trigger
A simple trigger that fires automatically when cells are edited in your spreadsheet.
onOpen Trigger
A simple trigger that runs when a user opens your Google Sheet.

Script Types & Tools

Bound Script
A script attached directly to a Google Sheet, accessible through the script editor.
Script Editor
The built-in IDE where you write, edit, and debug your Apps Script code.
Web App
A deployed Apps Script that can be accessed via URL, allowing external systems to interact with your script.
Custom Menu
A user-created menu in Google Sheets that triggers custom functions, typically added via onOpen.

Configuration & Limits

Manifest
A configuration file (appsscript.json) that defines your script's properties, including scope permissions.
Scope
The permissions your script requests to access Google services (Sheets, Drive, Gmail, etc.).
Quota
Daily execution limits for Apps Script, including runtime duration and API call limits.
Execution Log
A debugging tool in the script editor that shows when scripts ran, errors, and execution details.

Macros

Macro
Recorded actions in Google Sheets that can be replayed. While different from Apps Script, macros can be converted to Apps Script code for more advanced automation.