Yes. Google Sheets supports macros: you can record a sequence of spreadsheet actions and replay it, or customize the resulting Google Apps Script code for more control. In Google Sheets in a web browser, start at Extensions > Macros > Record macro.
What a Google Sheets macro is
A macro is a saved procedure for repeating work. In Sheets, recording a macro captures supported actions you perform in the spreadsheet, such as applying formatting or changing cell contents. You can then run that saved procedure instead of repeating each step by hand. It is useful when the same task comes up repeatedly in the same spreadsheet or in a consistent spreadsheet template.
Sheets macros are implemented with Google Apps Script, Google’s JavaScript-based environment for automating Google products. When you save a recorded macro, Sheets creates a script function in the spreadsheet’s associated Apps Script project. That means a macro is more than a playback recording: someone with appropriate access can inspect or edit its code, and a user who knows Apps Script can write an automation directly.
This is different from saying that Sheets runs every kind of macro. A VBA macro made for Microsoft Excel is not a Google Sheets macro, and Sheets does not execute VBA. A workbook’s Excel automation needs to be rewritten for Apps Script or handled in an Excel environment that supports VBA.
How to record and run a macro
To create a basic macro, open the spreadsheet in a desktop web browser and follow these steps:
- Select Extensions > Macros > Record macro.
- Choose whether to use absolute or relative references when the recording dialog offers that choice.
- Carry out the actions you want to repeat. For example, select a header row, apply bold formatting, and choose a fill color.
- Choose Save, give the macro a name, and save it. You can also assign an available keyboard shortcut during the save process.
- To run it later, select Extensions > Macros and choose the macro by name. If you assigned a shortcut, you can use that instead.
Try a new macro on a copy of the spreadsheet or on sample data first. A recorded action may affect a different range or values than you intended if the sheet’s layout has changed since you made the recording.
Absolute and relative references
The reference choice determines how a recorded action handles cell locations. An absolute reference repeats an action on the same recorded location. If the macro formats cells A1 through D1, for example, running it again generally targets that same range. This is a sensible choice for a fixed title area or a standard header in a template.
A relative reference bases the action on the current selection. If you record formatting for a row while using relative references, you can select another row before running the macro and apply the same kind of formatting there. This is handy when the target moves, but it also makes the starting selection important: running the macro with the wrong cell selected can apply actions in the wrong place.
Neither setting makes a macro automatically understand the meaning of your data. A macro does not inherently know that a newly added row is a total or that a column has moved. It follows its recorded instructions or the logic in its script. If your sheet changes shape often, test the macro against those changes and consider whether a more flexible script is needed.
What macros can and cannot automate
Macros are a good fit for repetitive, predictable operations that a user can perform in Sheets. Examples include applying a standard number format, setting column widths, adding consistent formatting to a report, or repeating a sequence of supported edits. They can save time when the work is routine and the spreadsheet structure is stable.
The recording feature does not capture every possible task or turn a sequence into a general-purpose program. Some actions may not be recorded as expected, and a recorded sequence may rely on the active sheet, selected cells, or a particular layout. If the automation needs decisions, loops, custom menus, or interactions with other Google services, editing the generated Apps Script or writing a script directly may be more appropriate.
For instance, a recorded macro could format a selected range as currency, but it will not automatically determine which rows contain new transactions unless its script includes logic to find them. Similarly, it will not infer how to handle an unexpected blank row or a renamed tab. Think of the recorder as a convenient starting point, not a substitute for checking the exact actions and assumptions.
Editing a macro and using Apps Script
To inspect or modify the script behind a macro, go to Extensions > Apps Script. The editor opens the spreadsheet’s script project, where you can find the function created for the macro. Changes to the script should be saved before you return to the spreadsheet and run the macro. A person unfamiliar with JavaScript should avoid making changes based only on guesswork; a small code error can prevent a function from running.
Apps Script can extend automation beyond what the recorder captures. A script can, for example, work with ranges programmatically or add a custom menu to a spreadsheet. The right approach depends on the task: use a recorded macro for a short, repeatable sequence; use a script when the job needs logic or capabilities that are not available in the recording interface.
Scripts can also prompt for authorization. If a macro or script needs access to spreadsheet data or another Google service, Google may ask the user to review and approve the requested permissions before the first run. Read the permission screen and understand what a script does before authorizing it, especially if the file came from someone you do not know.
Sharing, access, and safety
A macro belongs to the spreadsheet’s Apps Script project, rather than being a personal recording that automatically appears in every file. Sharing the spreadsheet is therefore central to sharing its automation. People who only have view access should not be expected to edit the macro or use it in the same way as spreadsheet editors. Script permissions and the actions a script performs can also affect whether each person needs to authorize it.
Before running a macro in a shared or unfamiliar file, check what it changes. A macro can alter spreadsheet contents, and a script may request broader access depending on what its code does. If a file is important, make a copy before experimenting. This is particularly useful when testing code that edits or clears ranges, because spreadsheet edits made by a script may not be recoverable through the normal undo history.
- Use macros only in files you trust, and review unfamiliar script code or ask its owner what it does.
- Test on a duplicate or noncritical data before applying a macro to a live report.
- Check the active sheet, selected range, and reference setting before running a macro that depends on them.
- When a script asks for permissions, consider whether those permissions make sense for the task.
Google Sheets macros versus Excel macros
The word “macro” is used in both products, but the underlying technologies differ. Google Sheets macros use Apps Script. Excel desktop macros commonly use Visual Basic for Applications (VBA). A VBA procedure cannot simply be pasted into a Sheets script project and expected to work; it uses a different language and different object model. Likewise, Apps Script code is not a VBA macro for Excel.
If you open or convert an Excel workbook that contains VBA, do not assume that the automation has been converted into a working Sheets macro. The spreadsheet data and formatting may be usable, but the VBA code does not become Apps Script automatically. Keep a separate original copy if preserving the Excel macro is important, and plan to rewrite and test the automation for the platform you intend to use.
Excel also has other automation options, including Office Scripts in supported Microsoft 365 environments, but these are distinct from both VBA and Google Apps Script. Choose the tool based on where the file will be used, what services the automation needs to access, and who must maintain it. For a Sheets-first workflow, Apps Script is the relevant scripting option.
Common problems and practical fixes
If a macro does not appear in the Extensions > Macros menu, first confirm that you are in the spreadsheet where it was created and that you have sufficient access. A macro saved in one spreadsheet is not automatically available in another. Also check whether the macro was actually saved and whether its script function still exists in the Apps Script project.
If it runs but changes the wrong cells, check whether the recording used absolute or relative references and what cell or range is selected when you start it. Then inspect the script for fixed sheet names, fixed ranges, or other assumptions. A renamed tab or rearranged columns can make an old macro target the wrong place even though the macro still runs.
If Sheets displays an authorization prompt, review it and approve only if you trust the script and the requested access is appropriate. If the macro fails with an error, open Extensions > Apps Script to review the function and its execution details. Apps Script has quotas and runtime limits that can affect larger or more complex automations; the applicable limits can vary by account type and service, so check Google’s current Apps Script quota documentation for a specific project.
Frequently Asked Questions
Can Google Sheets record a macro?
Yes. In a browser, choose Extensions > Macros > Record macro, perform the supported actions, and save the recording. Sheets stores it as an Apps Script function associated with that spreadsheet.
Can Google Sheets run Excel VBA macros?
No. Sheets does not execute VBA. To automate a Sheets file, use Apps Script or record a Sheets macro; VBA automation must be rewritten for the platform rather than assumed to convert.
Can I use the same macro in multiple Google Sheets files?
A recorded macro is associated with its spreadsheet’s script project, so it does not automatically appear in every file. You can copy or adapt script code for another spreadsheet, but check its references and permissions in the new file.
Do Google Sheets macros work on mobile?
The macro recording and Apps Script editing workflow is designed for Sheets in a desktop web browser. Use a browser to create or manage macros; do not assume the mobile app offers the same macro tools.
Why does my macro need permission to run?
Apps Script may request authorization when a function accesses spreadsheet data or other services. Review the request and the script’s purpose before approving it. The prompt can differ depending on what the code does and which account is running it.
Related
- Regression Analysis in Excel: Steps, Results, and Meaning
- Data Cleaning in Excel: Practical Techniques That Work
- Data Cleaning Steps in Excel: A Practical Guide
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Excel VBA Find Text in a String: InStr ExplainedIn Excel VBA, use the InStr function to find one piece of text inside another: it returns the…
- Excel VBA Find and Replace in a Range: Code and TipsTo find and replace text only within a chosen Excel range, use VBA’s Range.Replace method and call it…
- Excel VBA Error Handler: How to Catch and Fix ErrorsAn Excel VBA error handler is code that tells a macro what to do when a runtime error…
- VBA Resize Pictures to Fit in Excel Cells AutomaticallyTo resize pictures to fit inside Excel cells with VBA, run a macro that finds each picture, scales…
- VBA Range Offset: How to Select Cells Relative to a RangeIn VBA, Range.Offset(rowOffset, columnOffset) returns a range shifted from the original by the specified number of rows and…
- Easy Macro Recorder in Excel: How to Record and Use OneYes. Microsoft Excel for Microsoft 365 includes a built-in macro recorder: choose Developer > Record Macro, perform the…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.