Yes. Google Sheets can run macros: you can record a sequence of spreadsheet actions, save it, and run it again from the Sheets menu or an assigned keyboard shortcut. Sheets converts recorded macros into Google Apps Script code, so you can also inspect and edit the underlying automation.
What a Google Sheets macro does
A macro repeats a set of actions in a spreadsheet, such as applying a format, inserting a row, or cleaning up a range of data. Instead of performing the same clicks each time, you run the saved macro and let Sheets repeat the steps. It is useful for routine, predictable tasks, but it is not a recording of every action you take on your computer.
For example, suppose a weekly report arrives with dates in column A and sales figures in column B. A macro could apply a date format, bold the header row, adjust column widths, and add a border around the report. You could run it on the next report rather than repeat those formatting steps manually. The macro acts on the spreadsheet, so check which cells it targets before using it on a different layout.
Google Sheets macros are built on Apps Script, Google’s cloud-based scripting platform. A recorded macro is therefore more than a playback of mouse movements: Sheets saves script instructions that reproduce supported spreadsheet operations. You can keep using the macro as recorded, or edit its code for more control.
How to record a macro
Open the spreadsheet in Google Sheets in a web browser. The recording controls are under Extensions > Macros > Record macro. The recorder then captures supported actions in the sheet until you save the macro. A straightforward workflow is:
- Open the spreadsheet and choose Extensions > Macros > Record macro.
- Choose whether the macro should use absolute or relative cell references.
- Perform the spreadsheet actions you want to repeat, such as formatting a selected range or changing a cell value.
- Choose Save, enter a name, and optionally assign a keyboard shortcut.
Keep the recording focused. If you accidentally select the wrong range or perform an unrelated action, it may become part of the recorded sequence. It is often easier to stop, discard an unhelpful recording, and record a shorter, cleaner sequence than to try to work around mistakes later.
The exact actions the recorder can capture are not unlimited. It is designed for supported operations in Sheets, not for recording arbitrary browser activity, decisions, or interactions with other websites. If a task depends on conditions—such as treating rows differently depending on their contents—you may need to edit the script or use another method.
Absolute and relative references
When you record a macro, Sheets asks how to handle cell references. This choice affects where the macro acts when you run it later.
- Absolute references: the macro repeats actions on the specific cells or range involved in the recording. If you recorded formatting for A1:D10, running it again generally applies that action to that same range.
- Relative references: the macro performs actions in relation to the cell or range selected when you run it. This can help when the same operation should be applied to different sections of a sheet.
For instance, a macro recorded with relative references might be useful when you routinely format the block immediately to the right of the current selection. A macro that always styles the title row at the top of a report is more likely to suit absolute references. The choice does not make a macro intelligent: it will not identify a report’s changing boundaries unless its code is written to do so.
Before relying on either approach, test the macro on a copy or a small, safe part of the sheet. Pay special attention to the active cell and selected range when you run a relative-reference macro, because those determine where its actions begin.
How to run, manage, and edit macros
After saving a macro, run it from Extensions > Macros and choose its name. If you assigned a shortcut while saving, you can use that shortcut as well; Sheets displays the shortcut information in its macro controls. A macro runs in the spreadsheet where it was created, rather than acting as a universal command available in every file.
To change a macro’s name or shortcut, open Extensions > Macros > Manage macros. To examine or modify its code, open Extensions > Apps Script. The script project associated with the spreadsheet contains the functions used by its macros. Google Sheets identifies functions available for use as macros; a function generally needs to be a top-level function without parameters to be run as a macro.
Code editing allows changes that are difficult or impossible to capture with the recorder, such as looping through rows or checking a value before taking an action. However, changing script code can also change what the macro does. If you are unfamiliar with Apps Script, make a copy of the file first and ask someone with scripting experience to review complex changes. A macro that alters or clears cells can affect important data.
What macros can and cannot automate
Macros are a good fit for repeatable spreadsheet work with a stable sequence of steps. Common examples include applying consistent formatting, setting up a report layout, and repeating basic edits across a known range. If a task is simply a calculation, a spreadsheet formula may be easier to maintain than a macro; formulas update as their referenced data changes, while a macro typically runs only when invoked or triggered through an automation setup.
Macros also have limits. The recorder does not make a workflow adaptive just because the same steps are repeated. A sequence that assumes data always starts in row 2 can behave poorly if a new file includes extra title rows. A macro may also need to be edited when the sheet layout changes. For workflows involving conditions, external services, or timed actions, Apps Script can provide broader automation features, but those require code and are subject to Google’s current Apps Script services, permissions, and usage limits.
It is helpful to distinguish a macro from a trigger. A macro is a function a user can run from the spreadsheet controls or a shortcut. Apps Script triggers can run certain functions in response to events, such as an edit or a scheduled time, when configured appropriately. Triggers have their own setup, authorization, and limitations; recording a macro does not automatically schedule it to run.
Google Sheets macros compared with Excel macros
Google Sheets macros and Microsoft Excel macros both automate spreadsheet tasks, but they do not use the same scripting language. Sheets uses Apps Script, which is based on JavaScript. Traditional Excel macros commonly use Visual Basic for Applications (VBA). An Excel VBA macro cannot simply be imported into Google Sheets and run as-is; its logic usually needs to be rewritten in Apps Script or replaced with another approach.
Excel’s web and desktop capabilities differ too. Excel for the web can open workbooks containing VBA macros, but it cannot create, run, or edit VBA macros. Excel desktop for Microsoft 365 on Windows supports VBA. Microsoft also offers Office Scripts for some Microsoft 365 environments, but Office Scripts are a separate automation feature and are not interchangeable with either VBA or Google Apps Script.
For a small workflow tied to a shared Google spreadsheet, Sheets macros may be convenient because the script is associated with that file. If an organization already depends on Excel VBA, moving the workbook to Sheets involves more than uploading it: the macro code and sometimes the workflow itself must be adapted and checked.
Sharing, permissions, and safety
A spreadsheet’s macro and its Apps Script project are connected to that spreadsheet. People who can edit the spreadsheet may be able to work with its bound script, so treat the code as part of the file rather than as a private personal shortcut. Sharing the spreadsheet does not mean every user’s experience will be identical: a person may need to authorize the script under their own Google account before it can perform actions that require permission.
Authorization is a normal part of many Apps Script operations. Read the permission prompt and consider whether the script’s requested access makes sense for its purpose. Be cautious with macros or scripts from files you do not trust, particularly if they request access beyond what a formatting or data-cleanup task would seem to require. Organization administrators may also restrict Apps Script or related services in managed Google Workspace accounts.
Macros that change cells can produce results that are hard to reverse. Google Sheets does not provide a dependable undo history for every script action, so do not assume Ctrl+Z will restore everything a macro changed. Keep an untouched copy of important data, test new or edited macros on a duplicate, and review the target range before running them.
Costs and practical alternatives
There is no separate charge simply to record a macro in a Google Sheets file, but access to Sheets and Apps Script can depend on the Google account and organization using them. Workspace administrators can control available services, and Apps Script has quotas and limits that can vary by account type and change over time. A small recorded macro is unlikely to need extensive planning, while large or frequent automations should be checked against current Google documentation and organizational policies.
A macro is not always the simplest solution. Consider these alternatives:
- Formulas: Use them when the goal is to calculate or transform values dynamically as data changes.
- Built-in Sheets tools: Filters, conditional formatting, data validation, and pivot tables can handle many recurring tasks without code.
- Apps Script: Use a script when you need conditions, loops, custom menus, or integrations beyond what recording can capture.
- Manual steps: For a rare, short task, documenting a reliable procedure may be less effort than maintaining automation.
Choose a macro when the task is repetitive, the steps are predictable, and the relevant sheet layout is stable. If the process needs to interpret changing data or make decisions, plan for script editing or choose a tool designed for that requirement.
Frequently Asked Questions
Can I run an Excel macro in Google Sheets?
No, not directly if it is written in VBA. Google Sheets macros use Apps Script, so the code must be rewritten or the task recreated with Sheets features.
Do Google Sheets macros use VBA?
No. Recorded Sheets macros create Apps Script code, which is based on JavaScript. VBA is associated with Excel’s traditional macro system.
Can a Google Sheets macro run automatically?
A saved macro is normally run by a user from the Macros menu or its assigned shortcut. Automatic responses to edits or schedules require suitable Apps Script trigger setup and are subject to Google’s rules and limits.
Why does Sheets ask me to authorize a macro?
The script may need permission to access or change spreadsheet data or use another Google service. Review the requested access before approving it, especially when the file or script comes from someone else.
Can I edit a recorded macro?
Yes. Open the spreadsheet’s script project with Extensions > Apps Script to inspect or edit its code. Test changes on a copy, since code edits can alter or damage spreadsheet contents.
Will a macro work in every spreadsheet?
A macro is associated with the spreadsheet in which it was created. It may also rely on particular sheet names, cell ranges, or layout details, so copying it or using it on a different structure may require adjustments.
Related
- Data Cleaning Steps in Excel: A Practical Guide
- Outlook Excel Import: Move Spreadsheet Data Safely
- Outlook Excel Sheet: Create a Data Entry Form in Excel
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Excel VBA Find and Replace: Methods and ExamplesTo find and replace text with Excel VBA, use the Range.Replace method and specify what to search for,…
- Excel VBA Not Working? Diagnose Common Macro ProblemsIf Excel VBA is not working, first check that you are using the desktop version of Excel, the…
- Excel VBA Pivot Charts: How to Create and Refresh ThemYes—VBA can refresh, filter, and manage Excel PivotCharts, and you can create one by selecting a PivotTable and…
- Excel VBA: Find the Bottom Row of Data in a SheetTo find the bottom row in a particular Excel column, start at the worksheet’s last row and move…
- Excel VBA: Find a Column Number by Header Name in a RowTo find a column by its header in Excel VBA, search the header row with Range.Find and read…
- Excel VBA Sort Custom Order: How to Set It UpTo sort rows in a custom sequence with Excel VBA, add a sort field with the CustomOrder argument,…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.