Yes, you can use macros in Google Sheets in a web browser. Record a sequence of spreadsheet actions from Extensions > Macros > Record macro, save it, and run it later; Sheets stores the macro as Google Apps Script code attached to that spreadsheet.
What a Google Sheets macro is
A macro is a reusable set of instructions for carrying out repetitive work. For example, you might repeatedly format a monthly report, apply a standard header, set column widths, or clean up a range of cells. Instead of repeating each action by hand, you can run a saved macro to repeat the recorded steps.
Google Sheets macros are not the same technology as Excel VBA macros. Sheets uses Apps Script, a scripting platform based on JavaScript, while Excel desktop commonly uses Visual Basic for Applications (VBA). The Sheets recorder translates supported actions into Apps Script code. You can run the macro without understanding that code, but you can also open and edit it when the recorded version needs more flexibility.
A macro belongs to a particular spreadsheet rather than acting as a universal command for every file in your account. That makes it useful for recurring work in a template or operational workbook, but it also means a macro recorded for one sheet may need adjustment before it works properly in another spreadsheet with a different layout.
How to record and run a macro
Use Google Sheets in a desktop web browser for the full recording and management workflow. The main steps are:
- Open the spreadsheet and choose Extensions > Macros > Record macro.
- Choose whether the recording should use absolute or relative references. Absolute references point to specific cells; relative references make actions depend on the starting cell.
- Carry out the actions you want to repeat, such as applying a number format or changing a heading’s appearance.
- Choose Save, give the macro a name, and optionally assign a keyboard shortcut when prompted.
- To use it later, choose Extensions > Macros and select the macro by name. If you want to change its code, open Extensions > Apps Script.
For example, suppose each weekly report needs its title row bolded, a dark fill, and centered text. Start the recording with the title row selected, apply those formatting changes, then save the macro as something descriptive such as FormatTitleRow. When you run it again, check which cells it affects: whether the selection and recorded references are absolute or relative changes how reliably it applies to a new report.
Recording captures actions, not your intentions. If you select the wrong range, include an accidental click, or record steps that depend on a particular cell position, the macro may repeat those choices literally. It is worth doing a brief test on a copy or a safe sample range before relying on it in a live sheet.
Absolute versus relative references
The reference choice is one of the most important decisions during recording. An absolute-reference macro is suited to work that should always affect the same cells. For instance, if a workbook always has instructions in A1:D2 and you want to format that exact area, absolute references can make sense.
A relative-reference macro is useful when the same action should happen in relation to where you start. Imagine that every section of a sheet has a heading in the active row. If you start on the heading and record formatting for that row, relative behavior can help you apply the same formatting to a heading farther down the sheet. It does not mean the macro can identify headings by their text or make decisions; it simply follows recorded actions relative to the starting position.
Neither mode is automatically better. Choose based on the task, then test the macro from different starting cells if it is meant to be reusable. If results appear shifted, check the reference mode and the active selection before changing the script.
What macros can and cannot automate
Macros are a good fit for predictable actions that you repeat in a spreadsheet. Depending on what the recorder supports for a particular action, common examples include applying formatting, working with selected ranges, and repeating straightforward sheet edits. Once you edit the generated Apps Script, you can extend the automation with code, such as adding conditions or working with more than one range.
The recorder is not a way to capture every possible interaction with Google Sheets. A complicated workflow may include steps the recorder does not translate as expected, or actions that depend on the current layout, selection, or data. A recorded sequence also does not inherently understand a business rule. For example, it will not know that a row is a subtotal simply because it looks different unless the recorded actions or added code explicitly handle that rule.
Macros are usually run manually from the Extensions menu or an assigned shortcut. If you need a process to run automatically when a spreadsheet changes or on a schedule, that is a broader Apps Script task involving triggers. Triggers have their own setup, authorization, and service limitations, so automatic execution should not be assumed just because a macro has been recorded.
Editing macros with Apps Script
Every recorded macro is represented by a function in the spreadsheet’s Apps Script project. To inspect it, choose Extensions > Apps Script. The editor shows the script associated with the spreadsheet, where you can review the recorded steps, rename or adjust code, and save changes. Macro functions generally take no arguments when they are run through the Sheets macro interface.
Editing can help when a recorded macro is too rigid. For example, a recording might format a fixed range, while a revised script could determine the last populated row before applying a format. That requires writing and checking code; simply recording a sequence will not automatically make it adapt to changing data sizes. If you are unfamiliar with Apps Script, keep the original version or make a copy of the spreadsheet before modifying the project.
Apps Script code may request permission to access spreadsheet data or other Google services. The permissions depend on what the code does. Read the authorization request and review unfamiliar code before approving it, especially in a file received from someone else. Do not treat a macro as harmless solely because it appears in a spreadsheet.
Sharing, permissions, and safety
A macro is useful in a shared workbook when collaborators follow the same repeatable process. People with access to the spreadsheet may be able to use its macros, but a person who runs a script may need to authorize it under their own Google account. Access level, script behavior, and the services used can affect what a collaborator is able to do. If a colleague cannot run a macro, check their spreadsheet permissions and any authorization prompt rather than assuming the macro is missing.
Take particular care with scripts that send email, read or modify other files, or connect to external services. Apps Script can do more than format the visible cells, depending on the code and granted permissions. Before running code from an unfamiliar source, inspect it or ask a trusted administrator to review it. For important data, keep a clean backup or work in a duplicate file until the results are confirmed.
Also remember that spreadsheet edits made by a script may not behave like ordinary edits for undo purposes. Do not count on Ctrl+Z to reverse a macro’s changes. If a macro changes many cells or deletes information, a copy or a version history recovery may be safer than relying on undo.
Google Sheets macros compared with Excel macros
The two spreadsheet programs both offer automation, but their macro systems are not interchangeable. Google Sheets macros use Apps Script and are associated with a Sheets file. Excel macros commonly use VBA in the desktop application, and an Excel workbook containing VBA is typically saved in a macro-enabled format such as .xlsm. A VBA macro does not become a Sheets macro merely by importing its workbook into Google Sheets.
Excel for the web does not provide the same VBA authoring and execution experience as desktop Excel. Microsoft offers Office Scripts for some Excel web and Microsoft 365 workflows, but Office Scripts and Google Apps Script are different tools. If you are moving a process between Sheets and Excel, expect to rebuild and test its automation rather than assuming that code or recorded steps will transfer.
For a small, repetitive task that stays inside one Google spreadsheet, the built-in recorder is often the simplest starting point. If a task needs complex branching, external integrations, or automation across multiple Google services, Apps Script may be a better fit than a basic recording. For a one-off change, doing it manually may be easier and safer than creating a macro you will not reuse.
Common problems and practical fixes
If a macro seems to do nothing, first confirm that you are in the correct spreadsheet and that you selected the intended macro under Extensions > Macros. Check whether an authorization prompt is waiting, and make sure you have permission to edit or run the relevant script. A script error may also prevent later recorded steps from running.
If it changes the wrong cells, check the absolute or relative reference choice, the active cell, and the selection at the time you ran it. If it works in one copy of a sheet but not another, compare their layouts, tab names, and range sizes. A recorded action can rely on details that are not obvious from the macro’s name.
If the recorded steps are cumbersome to maintain, open the Apps Script editor and inspect the generated code. For a task with a growing number of exceptions, consider rewriting the logic rather than adding more recordings. Keep names clear, test changes on sample data, and preserve a backup when the spreadsheet is important.
Frequently Asked Questions
Are Google Sheets macros free?
Macros are a built-in Google Sheets feature, so you do not need to buy a separate macro product to record one. Apps Script services can have quotas or access requirements, and those details can depend on the account and the services your script uses.
Can I run a Google Sheets macro on my phone?
The full workflow for recording and managing macros is designed for Google Sheets in a web browser. The Android and iOS apps do not provide the same complete macro editing workflow, so use a desktop browser to record, inspect, or change a macro.
Can a Google Sheets macro run automatically?
A recorded macro normally runs when someone chooses it or uses its assigned shortcut. To run code automatically on a schedule or in response to an event, you generally need to set up Apps Script triggers and understand their permissions and limitations.
Can I use an Excel VBA macro in Google Sheets?
No, not directly. Google Sheets macros use Apps Script, whereas VBA is Excel’s macro language. You may be able to move the spreadsheet data, but the automation usually needs to be recreated in Apps Script or another suitable tool.
Can I undo a macro with Ctrl+Z?
Do not rely on Ctrl+Z to undo changes made by a script. Make a copy before running a macro that could affect important data, and use the copy or spreadsheet version history if you need to recover an earlier state.
Related
- Compound Interest Spreadsheet: Build One in Excel Easily
- Power Query: Select Columns and Keep the Fields You Need
- Google Sheets Data Cleaning: Tools, Steps, and Tips
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Excel VBA Find LookIn: What It Means and How to Use ItIn Excel VBA, LookIn is an argument of the Range.Find method that tells Excel what kind of content…
- Excel VBA: Find Unique Values in a ColumnTo find unique values in an Excel column with VBA, loop through the source cells, keep the first…
- Excel VBA: Find the Last Used Row in Any WorksheetTo find the last row containing content anywhere on a worksheet in Excel VBA, use Range.Find with SearchOrder:=xlByRows…
- Excel VBA: Match a Trendline Label to Its Line ColorYes. In Excel VBA, set the trendline label’s font color to the trendline’s line color: use Trendline.DataLabel.Font.Color and…
- Excel VBA Find Method: Syntax, Examples, and TipsIn Excel VBA, use the Range.Find method to search a range and return the first matching cell; if…
- Excel VBA New Line: Add Line Breaks in Cells and TextIn Excel VBA, join text with vbCrLf or vbNewLine to put it on separate lines in a message…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.