How to Add Macros to Google Sheets and Automate Tasks

VBA & macros · Updated November 3, 2026

How to Add Macros to Google Sheets and Automate Tasks

To add a macro in Google Sheets, open the spreadsheet in a desktop web browser, choose Extensions > Macros > Record macro, perform the actions you want to repeat, and save the recording. You can then run it from Extensions > Macros or assign it a keyboard shortcut. Macros are useful for repeating tasks such as formatting a report or applying the same layout to new data.

What You’ll Need

  • A Google account and a spreadsheet you can edit. View-only access is not enough to record or save a macro.
  • A desktop web browser with the spreadsheet open in Google Sheets. The mobile app does not provide the full macro-recording workflow.
  • A small, safe sample of the data or a copy of the spreadsheet. A macro can repeat changes quickly, so it is sensible to test it before using it on important information.

You do not need to write code to record a basic macro. Google Sheets saves the recording as a Google Apps Script function attached to that spreadsheet. This is different from an Excel VBA macro, and the two formats are not interchangeable.

Step-by-Step

  1. Open the right spreadsheet and prepare a test area. In a desktop browser, open the Google Sheets file where you want the macro to live. Check that you have editor access and that the file is not open in a restricted viewing mode. If the task will change or clear data, make a copy using File > Make a copy, or test on a duplicate tab first. Think through the actions you want to repeat and the cells they should affect. A short plan helps prevent recording unnecessary clicks.
  2. Start the macro recorder. In the Sheets menu, select Extensions > Macros > Record macro. A recording panel appears near the bottom of the sheet. If the Macros option is missing, confirm that you are using Google Sheets in a browser and have permission to edit the file. If it is still unavailable, reload the page or try a current desktop browser.
  3. Choose how the macro should treat cell references. In the recording panel, select either Use absolute references or Use relative references before performing the actions. Absolute references repeat actions on the same cells each time, such as formatting A1:D1. Relative references repeat the same pattern in relation to the cell selected when you run the macro, which is useful for applying a format to different rows or sections. Choose based on how you expect to reuse the macro; do not assume the recorder will infer your intention later.
  4. Perform only the actions you want repeated. Click the relevant cells or range, then use the Sheets menus and toolbar to carry out the task. For example, to make a report heading consistent, select the heading row, apply bold text, choose a fill color, and adjust alignment. For a repeatable number format, select the intended range and choose Format > Number. Avoid unrelated edits, exploratory clicks, or changes you do not want repeated. The recorder captures supported spreadsheet actions, not a general recording of everything you do on your computer.
  5. Stop recording as soon as the task is complete. Click Save in the recording panel. Do not continue editing after the intended sequence is finished, because those extra actions may become part of the macro. If you notice a mistake while recording, stop and save only if you want to inspect or edit the generated script; otherwise cancel the recording and start again with a clean sequence.
  6. Name and save the macro. In the save dialog, enter a short, descriptive name that begins with a letter and uses no spaces. For example, use FormatReportHeader rather than a vague name such as Macro1. You may also choose a keyboard shortcut number if Sheets offers that option. Click Save. The macro is now associated with the current spreadsheet, and Sheets creates or updates its bound Apps Script project behind the scenes.
  7. Run the macro from the menu first. Before relying on a shortcut, select Extensions > Macros and click the macro by its saved name. If the macro uses relative references, first select the cell or range that should serve as the starting point. If Google displays an authorization prompt, review the requested access and approve it only if you trust the spreadsheet and the script you just created. The first run may take longer while permissions are granted.
  8. Check the result and refine the workflow. Compare the affected cells with what you intended. Confirm that the macro used the right starting position, did not alter nearby data, and produced the same formatting or other changes you recorded. If it works, you can use the same menu command again or try the assigned shortcut. If the result is wrong, use Edit > Undo immediately where available, or restore your test copy, then record again with the correct reference setting and actions.

Common Mistakes

  • Choosing the wrong reference mode. An absolute-reference macro may keep changing the original cells even when you select a different area. A relative-reference macro may act in an unexpected place if you start from the wrong cell. Test both the intended starting point and one alternate location when the macro is meant to be reusable.
  • Recording too much. Extra selections, formatting changes, or menu actions can be included in the saved sequence. Keep the recording focused, and stop it as soon as the repeatable task is complete.
  • Expecting a macro to understand changing data. A recording repeats actions; it does not automatically decide which rows are new, identify every kind of exception, or adapt to a changed sheet layout. If the process needs that logic, the generated Apps Script may need to be edited, or a spreadsheet formula or other feature may be more appropriate.
  • Confusing Sheets macros with Excel macros. Google Sheets uses Apps Script, while Excel commonly uses VBA. A macro created in Sheets will not become an Excel VBA macro just because you download the spreadsheet as an Excel file.
  • Running it on live data before checking it. Some edits affect many cells at once. Test on a copy or a harmless range first, especially if the recorded steps clear, replace, or reformat information.

Tips

  • Use names that explain the task. Names such as ApplyCurrencyFormat or CleanNewRows are easier to identify in Extensions > Macros than default or generic labels, particularly when a file has several macros.
  • Keep the starting point obvious. For relative-reference macros, note which cell to select before running the macro. If other people use the sheet, add a short instruction in a nearby note or an instructions tab.
  • Build and test one small macro at a time. A short sequence is easier to verify and repair than a long recording that combines several unrelated jobs. Separate tasks such as formatting a heading and preparing a data-entry row into distinct macros.
  • Use the menu when a shortcut is inconvenient. A saved shortcut can save time, but it may be hard to remember or may conflict with browser or operating-system shortcuts. Extensions > Macros is a reliable way to see the available macros. If you use a shortcut, check the assignment shown when saving it; the key combination can differ by operating system.
  • Review the generated script only when needed. Choose Extensions > Apps Script to inspect or modify the code behind a macro. Editing the script is optional for ordinary recordings, but code changes should be made carefully and tested on a copy. The saved function must remain available to Sheets as a macro to appear in the macro menu.
  • Consider who can run it. A macro belongs to the spreadsheet’s bound script project. Collaborators may need editor access and may be asked to authorize it when they run it. Tell collaborators what the macro changes so they can review the action and any permission prompt.

Troubleshooting

The Record macro command is missing. Check that the file is a Google Sheets spreadsheet, not a preview or a file opened in view-only mode, and that you have editor permission. Open it in a desktop browser, refresh the page, and try again. If the spreadsheet is managed by a workplace or school, an administrator may restrict script features or authorization.

The macro does not appear in the menu after saving. Confirm that the save dialog completed and that you are looking in the same spreadsheet where you recorded it. Reopen Extensions > Macros after refreshing the page. If the macro was renamed or the script was edited, inspect Extensions > Apps Script and check that the relevant function still exists. Avoid deleting or renaming generated functions unless you understand how the macro menu uses them.

The macro runs, but changes the wrong cells. This is often a reference-mode or starting-selection problem. Check whether you recorded with absolute or relative references. For a relative macro, select the intended starting cell before running it. For an absolute macro, expect it to target the same recorded cells. If the action sequence itself is wrong, record a new macro on a test copy rather than repeatedly running it on live data.

A permission screen appears or the run is blocked. The first run may require you to authorize the Apps Script created for the spreadsheet. Read the prompt and proceed only if you recognize the file and expected actions. If an organization blocks authorization, contact its administrator rather than trying to bypass the restriction. A script that has been edited may request permissions beyond those needed for a simple recording, so review code changes before approving.

A shortcut does nothing. Run the macro from Extensions > Macros to separate a shortcut issue from a macro issue. Check that a shortcut was assigned and that the combination is supported on your operating system. Browser or system shortcuts can take precedence, so using the menu may be the simplest solution. Also make sure the spreadsheet is active and that you are not midway through editing a cell.

Frequently Asked Questions

Can I add a macro to Google Sheets without coding?
Yes. Use Extensions > Macros > Record macro, perform the actions, and save. Sheets generates the Apps Script code for the recorded sequence. You only need to edit code if the task requires behavior the recorder cannot capture.

Can a Google Sheets macro run automatically when I open the file?
A recorded macro does not automatically run when the spreadsheet opens. You can start it from Extensions > Macros or use its assigned shortcut. More advanced automation may require Apps Script triggers, which involve code and permissions rather than simply recording a macro.

Can I use the same macro in another spreadsheet?
Macros are attached to the spreadsheet in which they were created. They do not automatically become available in every file you open. To reuse the process elsewhere, record it in that spreadsheet or adapt the Apps Script for the other file, then test it before using it on important data.

Can I run a macro in the Google Sheets mobile app?
The mobile app does not offer the full desktop recording workflow. For recording, editing, and reliable macro management, use Google Sheets in a desktop web browser. If a task needs to run on mobile, check the available app features rather than assuming a desktop shortcut will work there.

Is a Google Sheets macro the same as an Excel macro?
No. Sheets macros use Google Apps Script, while Excel macros commonly use VBA. Downloading a Sheets file as an Excel workbook does not convert its Apps Script macro into VBA, so plan to recreate or adapt the automation for the other application.

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.