Level 3Apps ScriptReading, 6 min

Apps Script: your first automation

Formulas calculate. Apps Script does things: sends an email when a row changes, adds a menu, cleans up a tab every Monday at 7am. It's JavaScript that runs on Google's servers, connected to your sheet.

Open it from Extensions › Apps Script. Replace the starter code with:

function stampToday() {
  const sheet = SpreadsheetApp.getActiveSheet();
  const cell = sheet.getActiveCell();
  cell.setValue(new Date());
}

function onOpen() {
  SpreadsheetApp.getUi()
    .createMenu('Team tools')
    .addItem('Stamp today', 'stampToday')
    .addToUi();
}

Save, reload the sheet, and a Team tools menu appears. Click a cell, choose Stamp today, and today's date lands in it as a fixed value, not a TODAY() that changes tomorrow. The first run asks you to authorize the script to edit your spreadsheet.

Three ideas cover most automations:

  • Read and write ranges. sheet.getRange('A2:D50').getValues() gives you a 2D array; setValues writes one back. Work on arrays, then write once. It's far faster than cell by cell.
  • Triggers. onOpen and onEdit run automatically. Time-driven triggers (the clock icon in the editor) run a function hourly, daily or weekly.
  • Other Google apps. MailApp.sendEmail, CalendarApp and DriveApp work the same way.

Start small: one menu item that saves you five clicks a day. Keep your scripts in the sheet they serve, and add a comment at the top saying what each one does and who wrote it.