Scriptdrill

Google Apps Script guide, one page per job

Google Apps Script explained by the job you want done: read and write sheets, triggers, email, Drive, Calendar, fetching APIs, and the JavaScript you need for all of it, with the direct answer, working snippets, common errors, and the Scriptdrill exercises that practice the JavaScript.

40 topics, each with the direct answer, syntax, worked examples, the mistakes people make and the drills that practice it. Updated November 2026.

Getting started

  • What is Google Apps ScriptGoogle Apps Script explained for Sheets users: the JavaScript platform built into Google Workspace that automates Sheets, Gmail, Drive and Calendar.
  • Your first Apps ScriptWrite and run your first Google Apps Script in Sheets: open the editor, write a function that reads and writes cells, run it, authorize it and read the log.
  • Custom functionsCreate a custom function in Google Sheets with Apps Script: any function becomes a formula like =DOUBLE(A1), ranges arrive as 2D arrays, JSDoc adds help.
  • PropertiesServiceStore settings and secrets in Google Apps Script with PropertiesService: script, user and document properties, setProperty and getProperty, JSON values, keys.
  • Logger.log and console.logDebug Google Apps Script with Logger.log and console.log: where output appears, format placeholders, logging arrays and objects with JSON.stringify, logs.
  • Utilities.formatDateFormat dates in Google Apps Script with Utilities.formatDate: the time zone argument, Java pattern letters like yyyy MM dd HH mm, month names, MM versus mm.
  • try, catch and finallyHandle errors in Google Apps Script with try catch finally: catch exceptions from sheets, email and APIs, read err.message and err.stack, log and rethrow.
  • Deploy as a web appDeploy a Google Apps Script as a web app: write doGet and doPost, return HTML or JSON, read query and POST parameters, set who runs it and who can access it.

Reading and writing sheets

  • getRange and getValuesRead Google Sheets data with Apps Script: getRange by A1 notation or row and column numbers, then getValue for one cell or getValues for a 2D array of rows.
  • setValue and setValuesWrite data to Google Sheets with Apps Script: setValue for one cell, setValues for a 2D array that must match the range size, and the dimension error fix.
  • getLastRowFind the last used row in Google Sheets with Apps Script: getLastRow for the whole sheet, how it treats blanks and formulas, and the last row of one column.
  • appendRowAdd a row to a Google Sheet with Apps Script: appendRow for a single row after the last row with data, and setValues for many rows at once, with examples.
  • Loop through rowsLoop through rows in Google Sheets with Apps Script: read the data once with getValues, loop the 2D array with for, for...of or forEach, then write back.
  • Find a row by valueFind a row in Google Sheets with Apps Script: createTextFinder for an exact cell match, or findIndex on getValues for a column lookup, with the row number.
  • Delete rowsDelete rows in Google Sheets with Apps Script: deleteRow and deleteRows by position, delete rows that match a condition by looping from the bottom, blanks.
  • Copy data between sheetsCopy data between sheets or spreadsheets with Apps Script: range.copyTo for formats and formulas, getValues and setValues across files, copy a whole tab.
  • getActiveSheet vs getSheetByNameChoose between getActiveSheet and getSheetByName in Google Apps Script: when the active sheet is unreliable, targeting a tab by name, and missing sheets.
  • Protect ranges and sheetsProtect ranges and sheets with Google Apps Script: create a protection, remove everyone but yourself, add allowed editors, warning only, remove protections.
  • Clear and format cellsClear and format Google Sheets cells with Apps Script: clear content or formats, set background and font color, bold, number and date formats, borders.
  • Sort a rangeSort data in Google Sheets with Apps Script: range.sort by column number, descending order, multiple sort keys, sorting without the header, sorting an array.
  • Remove duplicatesRemove duplicate rows in Google Sheets with Apps Script: range.removeDuplicates for whole rows or chosen columns, or a JavaScript Set filter on one column.
  • Performance and batchingMake Google Apps Script faster: read and write in one getValues and setValues call, avoid getRange in loops, use flush and caching, beat the 6 minute limit.

Automation and triggers

  • onEdit triggerUse the onEdit trigger in Google Apps Script: the event object with range, value and oldValue, limiting it to one sheet or column, timestamps, installable.
  • onOpen and custom menusAdd a custom menu to Google Sheets with Apps Script onOpen: createMenu, addItem, separators and submenus that run your functions, and why a menu may hide.
  • Time-driven triggersSchedule Google Apps Script with time-driven triggers: create them in the Triggers panel or with ScriptApp.newTrigger, run daily, hourly or weekly, delete.
  • Installable triggersInstallable triggers in Google Apps Script: how they differ from simple triggers, creating them from the UI or ScriptApp.newTrigger, onChange, onFormSubmit.
  • Dialogs, prompts and sidebarsShow dialogs in Google Sheets with Apps Script: ui.alert for messages, ui.prompt for text input, Yes No buttons, and HtmlService dialogs and sidebars.
  • UrlFetchAppCall APIs from Google Apps Script with UrlFetchApp.fetch: GET and POST requests, headers and bearer tokens, JSON payloads, muteHttpExceptions, to a sheet.

Gmail, Drive and Calendar

  • Send email from a sheetSend email from Google Sheets with Apps Script: MailApp.sendEmail and GmailApp.sendEmail with HTML body, cc and attachments, loop a list of recipients, quota.
  • Gmail search and labelsAutomate Gmail with Apps Script: GmailApp.search with Gmail query syntax, loop threads and messages, read subject, sender and body, apply labels, archive.
  • Create a Google Doc from a templateGenerate Google Docs from a template with Apps Script: copy the template with DriveApp, replace {{placeholders}} with sheet values via DocumentApp, make PDFs.
  • List files in DriveList Google Drive files with Apps Script: get a folder by id, iterate getFiles with hasNext and next, read name, URL, size and dates, include subfolders.
  • Create calendar eventsCreate Google Calendar events from a sheet with Apps Script: CalendarApp.createEvent with start and end dates, all-day events, guests, avoiding duplicates.

JavaScript for Sheets

  • map, filter and reduceUse map, filter and reduce on Google Sheets data in Apps Script: transform rows, keep rows that match a condition, sum a column, chain them, write back.
  • forEach vs for loopsforEach, for, for...of and for...in in Google Apps Script: differences on 2D sheet data, when you need the index or an early break, why for...in fails.
  • Objects: keys, values and entriesWork with objects in Google Apps Script: turn sheet rows into objects by header, Object.keys, values and entries, Object.fromEntries, count or group rows.
  • String methodsString methods you need in Apps Script: trim, toLowerCase, split, join, includes, startsWith, replace with regex, slice, padStart and template literals.
  • Dates in Apps ScriptHandle dates in Google Apps Script: sheet dates arrive as Date objects, create dates with new Date(y, m, d), add days, days between, compare, time zone.
  • JSON.parse and JSON.stringifyUse JSON.parse and JSON.stringify in Google Apps Script: turn an API response into objects, write nested fields to a sheet, store objects as properties.
  • async, await and Promises in Apps ScriptAsync and Promises in Google Apps Script: the V8 runtime accepts async await syntax but every Google service is synchronous, so use UrlFetchApp.fetchAll.

Reading is not practicing

Every topic here links to drills that check your answer on live data. All of them are free to try.

Start practicing