To run a macro in Google Sheets, open the spreadsheet in a web browser, choose Extensions > Macros, and select the macro you want. If Google asks for permission the first time, review and authorize the script before running it; a macro repeats spreadsheet actions, so check the active sheet and selected cells first.
What a Google Sheets macro does
A macro automates a repeatable sequence of actions in a Google Sheets spreadsheet. For example, you could use one to format a weekly report, apply borders and number formats, resize columns, or sort a consistent data range. Instead of repeating those steps manually, you run the saved macro when you need them.
Google Sheets macros are implemented with Google Apps Script, Google’s JavaScript-based automation platform. Recording a macro creates a function in a script project associated with the spreadsheet. That makes a macro different from a formula: a formula calculates a result in cells, while a macro carries out actions when someone runs it. A macro does not automatically repeat whenever data changes unless you separately build an appropriate script or trigger.
Macros are saved with the spreadsheet rather than as a reusable feature in every file by default. If you copy the spreadsheet, review whether its macro and script project are present and usable in the copy. The actions a macro can perform depend on what was recorded or written in Apps Script, and a recorder cannot capture every possible task.
Run a macro from the menu
Use the desktop version of Google Sheets in a browser to access the standard macro menu. Open the spreadsheet and follow these steps:
- Choose Extensions > Macros.
- Select the macro by its name.
- If prompted, review the requested permissions and authorize the script with the Google account you intend to use.
- Wait for the operation to finish, then inspect the cells or sheets it changed.
The macro may take a moment to run, especially if it processes a large range or performs several operations. Avoid clicking Run repeatedly while it is working: doing so can repeat actions such as inserting rows, applying a sort, or changing values. If the menu has no macro names, the spreadsheet may not have any macros saved, or you may not have the necessary access. You can also use a keyboard shortcut if one has been assigned to the macro.
Before running it, check that you opened the intended spreadsheet and that the expected tab is active. Some recorded actions target fixed cells or switch between sheets; others use the active cell as their starting point. The name of a macro alone does not tell you which ranges it will change.
Record a macro for repeated work
To create a macro without writing code, open Extensions > Macros > Record macro. Sheets displays a recording panel while you perform the actions you want to automate. For example, to apply a standard header style, you might select the header row, make the text bold, set a fill color, and freeze the top row. When you are finished, use Save, give the macro a clear name, and optionally assign a shortcut.
The recorder offers a choice between using absolute references and relative references. This choice affects how the macro uses cell positions when it runs:
- Absolute references: Actions target the same cell locations used while recording. This is useful for a fixed summary area, such as formatting A1:F1 every time.
- Relative references: Actions are recorded in relation to the selected starting cell. This can help when applying the same pattern to different rows or sections, provided you start in the right place.
Test a new macro on a copy or a small sample before using it on important data. A quick test can reveal that the recording used a fixed range when you expected a relative one, or that it includes a step you did not intend. Use specific names such as FormatWeeklyHeader rather than generic labels that will be hard to distinguish later.
How recorded actions work
Recording is a way to generate script code from supported spreadsheet actions; it is not a video or a recording of every click. The resulting Apps Script function contains instructions that Sheets can run later. You can inspect or edit that code through Extensions > Apps Script. A basic recorded function may use Google’s Spreadsheet service to refer to a sheet or range and then apply formatting or other supported changes.
This matters when adapting a macro. A script can be changed to use a different range, handle more cases, or perform tasks the recorder does not expose. But code changes can also make the automation behave differently from its original recording. If you edit a function that appears in the macro list, test the updated version carefully. For a macro to appear as a runnable macro, it must be a suitable function in the spreadsheet’s bound Apps Script project; not every function in every script project is automatically a menu macro.
Macros are most useful when the task is predictable. If a report’s columns move around, a macro that always formats a hard-coded range may affect the wrong cells. In that situation, a script that locates a column by its header, or a spreadsheet template that keeps the layout consistent, may be more dependable.
Choose the right reference style and workflow
Think about whether the action belongs to a particular location or to a repeated pattern. If every monthly report places its title in A1, absolute references are usually easier to reason about. If you need to apply the same formatting to whichever row you start from, relative references may fit better. Either way, make the starting selection part of the procedure and tell other users where to click before running the macro.
Consider this example: a team receives a fresh list each Monday and wants the heading row bold with a colored background. If the headers always occupy A1:E1, a macro using absolute references can target that range. If each list begins at a different row and the user selects its header before running the macro, a relative recording may be more appropriate. Neither setting automatically detects the correct data; the macro follows its recorded or coded instructions.
For a process that changes often, document what the macro does and who is expected to run it. Keep a clean source template, and avoid relying on someone’s memory of a hidden setup step. If the workflow needs decisions, error handling, or automatic execution, consider whether a custom Apps Script function or a different tool is a better fit than a simple recording.
Permissions and sharing
On its first run, a macro may ask the user to authorize the Apps Script project. The permission prompt explains what access the script is requesting. Review it rather than approving blindly, particularly if the spreadsheet came from an unfamiliar source or the script has been edited. The authorization is associated with the user who grants it; sharing the spreadsheet does not mean every collaborator has already authorized the script.
People generally need permission to edit the spreadsheet to run or manage its macros. A viewer should not be treated as someone who can safely execute changes to the file. If collaborators report an authorization message, have them follow Google’s prompt using their own account, and verify that they have edit access. An administrator’s organization policies may also restrict Apps Script or access to certain services.
When you share a spreadsheet containing a macro, tell collaborators what it changes and when to run it. Do not include sensitive information in script code or grant broader access than the task needs. For business-critical automation, have someone responsible review the script and the permissions rather than assuming a recorded macro is harmless simply because it was created from menu actions.
Common problems and fixes
- The macro is missing: Confirm you are in the right spreadsheet, then check Extensions > Macros. If the script was recently edited, reload the spreadsheet and verify the function is still available as a macro.
- Authorization blocks the run: Read the permission prompt and authorize with an account that can edit the file. If an organization policy blocks the script, contact the administrator rather than trying to bypass the restriction.
- The wrong cells change: Check whether the recording used absolute or relative references, confirm the active sheet, and start from the expected cell. Review the function in Extensions > Apps Script if the behavior is still unclear.
- The result is incomplete: The recorder may not have captured every action, or the sheet layout may differ from the one used when recording. Repeat the process on a test copy and revise the recording or code.
- The macro appears to hang or run slowly: Large ranges and repeated script operations can take time. Do not immediately run it again; wait, check the result, and simplify the process or script if it consistently takes too long.
A useful first diagnostic is to reproduce the task manually on a duplicate spreadsheet and compare the result with the macro’s output. That helps separate a problem in the recorded steps from a changed sheet layout, missing permissions, or an expectation that the macro would work on a different range.
Safety, undo, and backups
A macro can make many changes quickly, which is its main benefit and its main risk. Before running unfamiliar code or a macro that edits important data, make a copy of the spreadsheet or test it on sample data. Check whether it sorts, clears, overwrites, inserts, or deletes anything, and confirm that those actions are intended.
Do not assume Ctrl+Z will reverse every change made by a script. Script-driven operations may not behave like ordinary manual edits in the undo history. If a result is wrong, use a backup or Google Sheets version history to recover where possible, and inspect the script before trying again. A copy is the simplest protection when the macro’s effects are uncertain.
Google Sheets macros compared with Excel
Google Sheets macros use Apps Script and are designed for Google Sheets. They are not Excel VBA macros, and VBA code cannot simply be pasted into a Sheets macro and expected to run. Excel has its own automation options, including VBA macros in desktop Excel and Office Scripts in supported Microsoft 365 environments; the right choice depends on where the spreadsheet is stored and which application the team uses.
If collaborators work primarily in Google Sheets through a browser, a Sheets macro keeps the workflow close to the file. If the process depends on Excel-specific features or VBA, Excel may be the more suitable environment. When converting or moving a workbook between products, check formulas, formatting, scripts, and automation separately; moving the visible cell data does not guarantee the macro will transfer.
Frequently Asked Questions
Can I run a Google Sheets macro on my phone?
Macro creation and the Extensions menu are intended for the desktop browser experience. The Sheets mobile apps may not expose the controls needed to run or manage a macro, so use Google Sheets in a computer browser for the standard workflow.
Do Google Sheets macros run automatically when a cell changes?
No, choosing a macro runs it on demand. Apps Script can use triggers for some automatic workflows, but setting up a trigger is a separate task and may require additional code, permissions, and testing.
Can I run a macro in every spreadsheet?
No. A macro belongs to the spreadsheet’s Apps Script project rather than being available in every file automatically. A spreadsheet without a macro will not show that macro in its Extensions > Macros menu.
Can I edit a recorded macro?
Yes. Open Extensions > Apps Script to inspect or change the associated code. Because a code edit can alter what the macro does, test it on a copy before using it on important information.
Are Google Sheets macros the same as Excel macros?
No. Sheets macros use Apps Script, while Excel macros commonly use VBA or, in supported environments, Office Scripts. The languages, features, and compatibility differ, so automation usually needs to be rewritten when moving between the two products.
Related
- IFS Syntax in Google Sheets: Examples and Common Errors
- IF vs IFS in Google Sheets: Which Formula Should You Use?
- Forward Google Sheets: What Happens When You Share?
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Excel VBA Activate Sheet: Syntax, Examples, and FixesTo activate a worksheet with VBA, reference it by name and call its Activate method: ThisWorkbook.Worksheets("Summary").Activate. The sheet…
- Delete the Last Row in Excel VBA SafelyTo delete the last data row of an Excel table, use the table’s ListRows collection: tbl.ListRows(tbl.ListRows.Count).Delete. For a…
- Excel VBA Shortcut: Open the Editor and Run MacrosIn Excel for Windows, press Alt+F11 to open the Visual Basic Editor (VBE), where you can view and…
- VBA Function List: Built-In Functions, Groups, and UseA VBA function list is a reference to built-in functions you can call from Visual Basic for Applications,…
- VBA Range Object: How to Work with CellsThe Excel VBA Range object represents one or more cells on a worksheet, letting code read or change…
- Word VBA: How to Add and Format Headers in a DocumentTo add a header with Word VBA, set the header range’s text, for example ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Text = "Quarterly Report".…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.