Google Sheets Script Macros: How to Use & Record

VBA & macros · Updated November 23, 2026

Google Sheets macros are automated sequences of actions you can record or write in Google Apps Script, then run with a single click or keyboard shortcut. They work by translating your spreadsheet actions into Apps Script code, which you can edit, reuse, and share. This article explains how to record, run, and manage macros, how they differ from Excel VBA, and how to write your own scripts for tasks that recording can’t handle.

What Are Google Sheets Macros?

Macros in Google Sheets let you automate repetitive tasks like formatting, inserting rows, or applying filters. When you record a macro, Sheets captures your actions and converts them into a function in Apps Script (a JavaScript-based language). The macro is stored in the spreadsheet’s container-bound script, and you can run it from the Tools > Macros menu or assign it to a custom keyboard shortcut.

Unlike Excel’s VBA macros, Google Sheets macros are not stored in a separate file; they live inside the spreadsheet itself. This means they are tied to that specific spreadsheet, but you can copy them to other sheets by copying the script.

How to Record a Macro in Google Sheets

Recording is the easiest way to create a macro without writing code. Here are the steps:

  1. Open your Google Sheet in a browser.
  2. Go to Extensions > Macros > Record macro.
  3. Use the spreadsheet normally: click cells, apply formatting, insert rows, etc. The recorder captures your actions.
  4. When finished, click Save.
  5. Name your macro, optionally add a custom shortcut (like Ctrl+Alt+Shift+1), and click Save.

After recording, the macro appears under Extensions > Macros. You can run it by selecting it from that menu or using the assigned shortcut. Note that the recorder captures absolute references by default, meaning it will affect the same cells you clicked. For relative references (e.g., always format the current row), you need to edit the script.

Editing the Generated Apps Script

When you record a macro, Sheets creates a function in the script editor. To view it, go to Extensions > Apps Script. You’ll see a function named something like MyMacro that contains calls to the SpreadsheetApp service. For example, a macro that bolds cell A1 might look like this:

function MyMacro() {
  var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.getRange('A1').activate();
  spreadsheet.getActiveRange().setFontWeight('bold');
}

You can edit this code directly to change the range, add loops, or use variables. For instance, to make the macro bold the current cell, you’d replace getRange('A1') with getActiveRange(). After editing, save the script and run the macro from the menu again.

Writing Custom Macros (Apps Script Basics)

For tasks that recording can’t handle (like looping through rows or fetching data), you write custom functions in Apps Script. Here’s a simple example that formats all cells in column A to bold:

function formatColumnA() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var range = sheet.getRange('A:A');
  range.setFontWeight('bold');
}

To use this, open Extensions > Apps Script, paste the code, save, and then run the function from the script editor or from the Macros menu (after adding it as a macro). You can also trigger scripts from buttons or time-driven triggers.

Macros vs. Custom Functions vs. Add-ons

It’s easy to confuse macros with other automation tools. Here’s a clear breakdown:

  • Macros: Recorded or written scripts that manipulate the spreadsheet interface; they run from the menu or shortcut.
  • Custom functions: User-defined functions like =MYFUNCTION(A1) that return values; they are written in Apps Script but cannot change the spreadsheet structure (e.g., can’t insert rows).
  • Add-ons: Pre-built extensions that provide additional features; they are essentially packaged scripts that can be installed from the Google Workspace Marketplace.

For most automation, macros are sufficient. For complex data processing, you might combine macros with custom functions.

Common Problems and Limitations

Macros have several quirks you should know:

  • Recording doesn’t capture everything: Some actions like scrolling or changing tabs are not recorded. Also, macros cannot record actions that require authorization (like sending emails) unless you write code.
  • Absolute vs. relative references: By default, recorded macros use absolute references. To make a macro act on the selected cell, you must edit the script to use getActiveRange() instead of a fixed range.
  • Undo limitation: Macros cannot be undone with Ctrl+Z. Always test on a copy of your data.
  • Performance: Macros that process large ranges can be slow. Use batch operations like setValues() instead of looping cell-by-cell.

Comparing Google Sheets Macros to Excel VBA

If you’re coming from Excel, the differences are significant:

  • Language: Excel uses VBA (Visual Basic for Applications); Google Sheets uses Apps Script (JavaScript).
  • Storage: Excel macros are stored in the workbook or a personal macro workbook; Google Sheets macros are stored in the spreadsheet’s script.
  • Recording: Excel’s recorder is more feature-rich; Google Sheets’ recorder is simpler but still useful.
  • Access: Google Sheets macros are cloud-based and run in the browser; Excel macros run locally.
  • Compatibility: You cannot directly convert VBA to Apps Script; you must rewrite the code.

For simple tasks, Google Sheets macros are easier to share because they’re stored in the sheet. For complex automation, Excel VBA offers more control over the desktop environment.

Costs and Sharing

Google Sheets macros are free for all users with a Google account. However, if you use Apps Script heavily, you may hit quotas (e.g., 20,000 seconds of execution time per day for free accounts). For business use, Google Workspace plans provide higher quotas. Macros are shared with anyone who can edit the spreadsheet; viewers cannot run macros unless you grant them edit access.

Safety and Permissions

When you run a macro that does more than simple formatting, Google asks for permission to access your data. Always review the permissions and ensure the script comes from a trusted source. Malicious macros can delete data or send emails. To stay safe:

  • Only run macros from spreadsheets you trust.
  • Before running a new macro, make a copy of your spreadsheet.
  • Review the code in Apps Script if you’re unsure what it does.

Frequently Asked Questions

Can I record a macro that works on any selected cell? Yes, but you need to edit the script. Replace fixed ranges like getRange('A1') with getActiveRange() or getCurrentCell() to make the macro act on the current selection.

How do I assign a keyboard shortcut to a macro? When you record and save a macro, you can set a shortcut. For existing macros, go to Extensions > Macros > Manage macros, click the three-dot menu, and select Edit to change the shortcut.

Can I use macros in the Google Sheets mobile app? No, macros can only be recorded and run in the web browser version. The mobile app does not support macros.

Why is my macro not running? Common reasons: you don’t have edit permissions, the script has errors, or you haven’t authorized the script. Check the Apps Script editor for errors and run the function from there to see error messages.

Can I copy a macro to another spreadsheet? Yes. Open the spreadsheet with the macro, go to Extensions > Apps Script, copy the code, then paste it into the script editor of the other spreadsheet. Alternatively, use Tools > Macros > Import to import macros from another spreadsheet (if you have access).

Are macros the same as scripts? Macros are a type of script, but not all scripts are macros. Macros are triggered from the UI and are meant for recording; scripts can be standalone functions or triggers.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.