To run a macro in Google Sheets, open the spreadsheet in a desktop web browser, choose Extensions > Macros, then select the macro you want. If it is the first run, review and approve the requested permissions. A macro repeats recorded spreadsheet actions, helping you apply the same formatting or workflow without doing each step manually.
You can also create a macro before running it: choose Extensions > Macros > Record macro, perform the actions, save the recording, and give it a name. Google Sheets stores macros as Apps Script code in that spreadsheet. They are not Excel VBA macros, so an Excel macro will not run in Sheets as-is.
What You’ll Need
- A Google account with access to the spreadsheet. You generally need editor access to create or run a macro.
- A desktop web browser and a Google Sheets spreadsheet. The Sheets mobile app does not provide the full macro recording and management workflow.
- A saved macro in the spreadsheet, unless you are going to record one now. If you are using an Excel file, convert it to Google Sheets format first; an .xlsx file’s VBA macros are not supported.
- Permission to authorize the macro if Google asks you to approve its Apps Script access. In a work or school account, an administrator may restrict scripts.
Step-by-Step
- Open the correct spreadsheet. In a desktop browser, open Google Sheets and load the file that contains the macro. Macros belong to the spreadsheet where they were created, so opening a different file can mean the macro is not in its menu. If you have an Excel workbook, convert it using File > Save as Google Sheets when that option is available, then check whether you need to recreate the macro. Conversion does not make VBA code executable in Sheets.
- Check that the file is ready for the macro. Confirm that you have editor access and that the sheet, columns, and data are in the expected state. A recorded macro may refer to specific cells or ranges. For example, a macro that formats a header in row 1 may apply its formatting to the wrong cells if your current layout has shifted. If the macro is intended for a particular tab, open that tab before running it.
- Find the macro in the menu. Select Extensions > Macros. The menu lists macros saved in the current spreadsheet. Click the one you want to run. If a shortcut was assigned when the macro was saved, you can use that shortcut instead, but the menu is the clearest option when you are learning or checking which macro you selected. If the macro is missing, see the troubleshooting section below.
- Authorize the script if prompted. On a first run, Google may show a permissions window describing what the script can access. Check that you recognize the spreadsheet and the action you are authorizing, then follow the prompts to select your account and allow access if you trust the macro. The exact prompt can vary with the script and account settings. Do not approve an unfamiliar script simply to make the prompt disappear; ask the file owner what it does first. A managed work account may require an administrator to allow it.
- Wait for the run to finish. A small notification may appear, or the sheet may visibly change as the actions are applied. A short formatting macro can finish quickly, while one that processes many cells may take longer. Avoid clicking Run repeatedly just because there is no immediate visual change: a second run could repeat the action, duplicate content, or apply formatting twice. Check the affected tab and range before deciding whether another run is needed.
- Verify the result. Compare the output with what you intended. Check the relevant cells, formulas, formatting, and any other sheet the macro is expected to affect. If a macro sorts or edits data, confirm that the correct range was included and that related rows stayed together. If something is wrong, use the spreadsheet’s version history or undo if available and appropriate, then inspect the macro before running it again. Do not assume every script action can be undone with the Undo command.
- Record a macro if the spreadsheet does not have one. Choose Extensions > Macros > Record macro. In the recording controls, choose whether to use absolute references or relative references. Absolute references target the same cells each time; relative references replay actions in relation to the cell selected when you run the macro. Perform only the actions you want captured, such as selecting a range and applying a number format. When finished, click Save macro, enter a clear name, optionally assign a keyboard shortcut, and save. The new macro should then appear under Extensions > Macros.
- Run and refine the new recording. Select a suitable starting cell or range if you chose relative references, then run the macro from Extensions > Macros. Check what it changed. If the recording does not behave consistently, record it again with the correct reference setting and a clean, predictable sequence of actions. Keep names descriptive, such as “Format monthly header,” so you can distinguish similar tasks in the menu.
Common Mistakes
- Looking in the wrong spreadsheet. A macro is associated with its spreadsheet, not automatically available in every file in your Drive. Open the file where it was created.
- Expecting Excel VBA to work. Google Sheets macros use Apps Script. Changing the file extension or uploading an .xlsm workbook does not convert its VBA into a Sheets macro.
- Choosing the wrong reference behavior. Absolute references repeatedly affect fixed locations; relative references act in relation to the starting selection. A macro recorded for one cell layout may misfire if run from another.
- Recording extra clicks or selections. The recorder captures actions, so unnecessary navigation or edits can become part of the macro. Start with the sheet in a known state and keep the recording focused.
- Running it several times without checking. Some actions are not harmless when repeated. A macro that inserts rows, copies values, or changes a range may produce a different result on each run.
- Ignoring the permissions prompt. Authorization gives a script access described in the prompt. Only approve scripts you trust and understand, especially in spreadsheets shared by someone else.
Tips
- Test on a copy. Before using a macro on important or shared data, make a copy of the spreadsheet with File > Make a copy and run the macro there. Check the result before using it on the working file.
- Use a repeatable starting point. Write down which tab and cell should be selected before running a relative-reference macro. Consistent starting conditions make recorded actions more predictable.
- Keep the data layout stable. If the macro works on a fixed range, avoid inserting or moving columns without checking the macro afterward. Consider using a fresh recording when the sheet structure changes significantly.
- Choose clear names and shortcuts. A name should describe the task, not just its sequence, such as “Apply invoice formatting.” A shortcut can save time for a frequently used macro, but the menu remains useful when you are unsure which one to run.
- Inspect the script when needed. Choose Extensions > Apps Script to view the code associated with the spreadsheet. Recorded macros are represented as Apps Script functions. If you edit code, make a copy first and avoid changing code you do not understand; a coding error can stop the macro from running.
- Separate repetitive tasks. A focused macro for formatting is easier to check than one long recording that formats, sorts, and changes several tabs. Smaller tasks also make it easier to identify which action caused an unexpected result.
Troubleshooting
- The Extensions menu or Macros option is missing: Make sure you have opened the file in Google Sheets in a desktop browser, not just previewed it in Drive or opened it in the mobile app. If the file is still an Excel workbook, convert it to Google Sheets format. Also check whether you have edit access and whether your organization restricts Apps Script.
- The macro does not appear in the list: Confirm that you are in the spreadsheet where it was created and refresh the browser tab. If someone shared a different spreadsheet with you, its macros are not automatically copied into yours. The owner can explain where the macro lives or help you recreate it in the intended file.
- Google shows an authorization or access error: Read the requested permissions and make sure you are signed in to the account that can edit the file. If you trust the script, follow the authorization flow. If the approval is blocked by a work or school policy, contact the administrator rather than trying to bypass the restriction.
- The macro runs but changes the wrong cells: Check whether the recording used absolute or relative references, and confirm the active tab and selected cell before running it. If your sheet layout has changed, make a copy and record the actions again using the right reference option.
- The macro stops with an error: Look for an error notification and open Extensions > Apps Script to inspect the script or execution details if available. The error may be caused by a renamed tab, deleted range, missing permission, or a change in the sheet layout. Restore the expected sheet structure or update the script only if you understand the change required.
- You cannot restore the previous result: Macro actions are not guaranteed to be reversible with Undo. Check File > Version history > See version history to review or restore an earlier version, taking care not to discard other people’s later edits. This is why testing on a copy is important.
Frequently Asked Questions
How do I run a macro in Google Sheets?
Open the spreadsheet in a desktop browser, choose Extensions > Macros, and select the macro. Approve the requested permissions if this is its first run and you trust the script.
Can I run a macro in Google Sheets on my phone?
The mobile app does not offer the full macro recording and management workflow. Use Google Sheets in a desktop web browser to access the macro menu and run or record macros.
Can Google Sheets run Excel VBA macros?
No. Sheets macros use Apps Script, while Excel macros commonly use VBA. You can convert an Excel file’s spreadsheet data, but you need to recreate or rewrite its macro for Google Sheets.
Do I need to record a macro before I can run one?
No. If the current spreadsheet already contains a macro you can access, select it from Extensions > Macros. Record one only when you need to create a new repeatable task.
Why does Google ask me to authorize a macro?
A macro is Apps Script code, and it may need permission to read or change spreadsheet data. Review the requested access and approve it only if you trust the script and its source.
Can I undo a macro in Google Sheets?
Not reliably. Some macro actions may be reversible, but others are not restored by Undo. Test on a copy first, and use version history if you need to recover an earlier spreadsheet state.
Related
- How to Clear Cache in Outlook Calendar
- How to Clear the Cache in Outlook on Windows and Mac
- How to Clear Cache in the Outlook Desktop App Safely
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Copy Paste Values in Excel VBA: Methods and ExamplesTo copy a range’s results—not its formulas—in Excel VBA, use Copy followed by PasteSpecial Paste:=xlPasteValues. For a quick…
- VBA Outlook: How to Create a Contact GroupIn classic Outlook for Windows, VBA can create a contact group by making an Outlook DistListItem, adding resolved…
- Running Macros in Google Sheets: How to Run and Manage ThemTo run a macro in Google Sheets, open the spreadsheet in a web browser, choose Extensions > Macros,…
- VBA Range Filter: How to Use AutoFilterTo filter a worksheet range with VBA in Excel for Microsoft 365 on Windows, call the range’s AutoFilter…
- Excel VBA AutoFit: Resize Rows and Columns AutomaticallyIn Excel VBA, use the AutoFit method on the rows or columns you want to size. For example,…
- Excel Macro Message Box: How to Create and Use OneAn Excel macro message box is a pop-up created with VBA’s MsgBox function. In Excel for Microsoft 365…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.