Google Sheets macros use Google Apps Script, a scripting language based on JavaScript; there is no separate Google Sheets macro language. Recording a macro creates an Apps Script function that replays supported spreadsheet actions, and you can edit that function or write one yourself for more control.
What a Google Sheets macro is
A macro is a named sequence of actions that can be run again in a spreadsheet. For example, a macro might bold a heading row, apply a number format, resize columns, and freeze the top row. Instead of repeating those steps by hand, you run the macro when needed.
In Google Sheets, macros are a feature of Apps Script. When you record a macro, Sheets creates a script in an Apps Script project associated with that spreadsheet. The script uses Apps Script services to interact with the sheet, such as the Spreadsheet service, rather than storing a recording as a separate kind of file.
This distinction matters when looking for instructions or deciding what to learn. Tutorials about Google Sheets macros generally use JavaScript syntax and Apps Script APIs. Excel VBA code is not the language used by Sheets macros, and an Excel macro cannot simply be pasted into a Google Sheets script and expected to run.
How recording a macro works
To record one in the Google Sheets web interface, open the spreadsheet and choose Extensions > Macros > Record macro. Perform the actions you want to capture, then choose whether to use absolute or relative references when that option is presented and save the macro with a name. Sheets then generates a function in the spreadsheet’s Apps Script project.
Absolute references target the same cells each time. If a recording formats A1:D1, an absolute reference will continue to target that range. Relative references make actions depend on the selected cell when the macro runs, which is useful when applying the same operation to different rows or sections. The choice is about how recorded cell references behave; it does not make every action in the macro relative.
Recording is convenient, but it does not capture every possible intention. It records supported actions as code, not a general description such as “format any row whose status is overdue.” If you need conditions, repeated processing, or decisions based on cell values, you will usually need to edit the generated script or write a function yourself.
What Apps Script is based on
Apps Script is Google’s cloud-based scripting platform, and its language is based on JavaScript. Apps Script’s V8 runtime supports modern JavaScript syntax, but Apps Script is not simply a browser page or a Node.js project. It provides Google-specific services and APIs, such as SpreadsheetApp, for working with Google Sheets and other Google services.
A small macro function can look like this:
function formatHeader() {
const sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange('A1:D1').setFontWeight('bold');
}
This function gets the active sheet, selects A1:D1, and sets the text weight to bold. The function name is the label used to identify the task; the statements inside the braces tell Apps Script what to do. Apps Script methods and services are documented separately from standard JavaScript, so learning JavaScript syntax is helpful but does not replace learning the Sheets API.
How to edit or create a macro
Choose Extensions > Apps Script to open the script project attached to the spreadsheet. A recorded macro’s generated function can be inspected and changed there. You can also add a function in the editor, save the project, and then make it available through the macro menu by choosing Extensions > Macros > Import macro and selecting the function. Menu labels can change as Google updates its interface, but these are the standard web-app paths.
After editing, return to the spreadsheet and run the macro using Extensions > Macros and its name. On its first run, a script may ask for authorization to access the spreadsheet or other services it uses. Review the requested permissions before approving them. If a macro does not appear in the menu, check that the project was saved, that the function is eligible to be imported, and that you imported it into the spreadsheet’s macro list.
Recorded macros generally operate on the active spreadsheet and selection. That can be useful for a personal workflow, but it can also make a script sensitive to which tab or cells are active. If the task should always affect a particular sheet, edit the code to identify that sheet explicitly and consider checking that it exists before changing data.
When a macro is enough—and when to write more code
A recorded macro is a good fit for a repeatable, mostly fixed sequence of formatting or editing actions. Examples include applying a standard report layout, clearing a known input range, or adding consistent borders to a selected table. It lets a user automate a routine without first designing a complete program.
More involved work calls for deliberate scripting. Apps Script can use variables, conditions, loops, and functions to make decisions or process ranges. For example, a custom function could inspect a column and highlight only rows marked “Needs review.” That logic is different from recording a fixed series of clicks: the script must read the values, test each one, and apply the desired change.
- Choose recording when the steps are predictable and you want a quick way to repeat them.
- Edit the generated script when you need to adjust ranges, sheet names, or a few details that recording cannot express well.
- Write a script from scratch when the task needs conditions, loops, custom menus, or interaction with another Google service.
- Use formulas or built-in Sheets features when the goal is calculation, sorting, filtering, or formatting that updates automatically. A macro is not always the simplest tool.
Running macros, shortcuts, and automation
You can run a saved macro from Extensions > Macros. Google Sheets also lets you assign a macro shortcut through Extensions > Macros > Manage macros. The available shortcuts use a numbered Ctrl+Alt+Shift combination; browser, operating-system, and keyboard settings can affect whether a particular combination is convenient or intercepted elsewhere.
A macro is typically started by a user, while Apps Script offers other ways to automate work, including installable triggers and time-driven triggers. These are not the same as the basic macro recorder. A trigger may run a function when an event occurs or on a schedule, subject to Apps Script authorization and service limits. Use triggers only when automatic execution is genuinely useful, because an unattended script can make changes without someone checking each step.
Macros run in Google Sheets, which is a browser-based service. They are not a feature that runs inside an exported .xlsx copy. If you download a spreadsheet to Excel, its Apps Script project does not become VBA code or an Excel macro. Likewise, editing a downloaded workbook in Excel does not update the Apps Script project in the original Google Sheet.
Google Sheets macros compared with Excel macros
In Microsoft Excel, traditional macros are commonly written in Visual Basic for Applications (VBA). Google Sheets macros use Apps Script, which is based on JavaScript. Both can automate spreadsheet tasks, but their languages, programming interfaces, hosting models, and file formats differ. Code written for one environment generally needs to be rewritten for the other.
Excel for Microsoft 365 also has Office Scripts, which use TypeScript and are designed for supported Microsoft 365 workflows. Office Scripts are distinct from VBA and from Apps Script. When choosing between tools, consider where the workbook lives, which collaborators need to run the automation, the services it must connect to, and the organization’s security rules—not just which language looks more familiar.
For a spreadsheet that stays in Google Sheets and uses Google services, Apps Script is the natural scripting option. For a workbook that must operate in Excel with existing VBA procedures, VBA may be more appropriate. If a team shares files across platforms, verify that the required automation can be maintained on each platform rather than assuming a macro will travel with the sheet.
Permissions, privacy, and practical limits
Apps Script can request permission to read or change spreadsheet data and, depending on the code, access other Google services. A recorded macro that only formats cells has a narrower purpose than a script that sends email or reads files, but users should still inspect unfamiliar code and permission prompts. Do not run scripts from an unknown source merely because they are attached to a spreadsheet someone shared.
Scripts are also subject to Apps Script quotas and execution limits. The applicable limits depend on the account type, service, and current Google policies, and Google can revise them. A macro intended for a small table may be too slow or exceed limits when applied to a very large data set. For larger jobs, efficient range operations—reading or writing a whole range at a time instead of handling each cell separately—are often preferable.
Sharing a spreadsheet does not automatically mean every collaborator can authorize and run every script in the same way. Their access level, account settings, and organization administrator policies can matter. If a macro is important to a team workflow, document what it changes, who owns the script, and what to do if authorization or access is blocked.
Costs and alternatives
Apps Script is included as part of Google’s scripting platform; there is not generally a separate per-macro purchase. Access to Google Sheets and related services may depend on whether someone uses a personal Google account or a Google Workspace account, and Workspace plans and administrator controls can vary. Quotas and availability should be checked against Google’s current documentation for the account in use.
Before writing a macro, consider whether a built-in Sheets tool is simpler. Filter views and sorting can handle many data-navigation tasks; conditional formatting can apply visual rules automatically; formulas can calculate results as source data changes. A recorded macro is strongest when a user needs to repeat a sequence of actions, not when a built-in feature already keeps the result up to date.
Frequently Asked Questions
Is Google Sheets macro language JavaScript?
It is based on JavaScript and runs in Apps Script, Google’s scripting environment. It also uses Google-specific services such as SpreadsheetApp, so ordinary JavaScript knowledge helps, but Apps Script APIs and permissions have their own rules.
Can I use VBA in Google Sheets?
No. VBA is Excel’s traditional macro language and does not run as a Google Sheets macro. To automate a Google Sheet, use Apps Script or a Sheets feature. Moving automation between Excel and Sheets normally requires translating or rewriting the code.
Where do I find the code behind a recorded macro?
Open the spreadsheet and choose Extensions > Apps Script. The associated script project contains the function created by the recorder. You can review or edit it there, then save the project and run the macro from the spreadsheet.
Do macros run automatically when a sheet opens?
A regular recorded macro does not automatically run just because someone opens the spreadsheet. Apps Script triggers can support some automatic workflows, but they must be configured appropriately and may require authorization. A trigger is a separate automation mechanism, not an automatic property of every recorded macro.
Why is my macro not visible or not running?
Check that the script project and macro list are saved, that the function was imported if you created it manually, and that you are using the correct spreadsheet. On an initial run, complete any legitimate authorization prompt. Also check for syntax errors, renamed sheets, missing access, or organization restrictions; a script that refers to a sheet or range that no longer exists may fail.
Related
- Google Sheets List Without Duplicates Using UNIQUE
- Google Sheets Last Updated Timestamp: How to Find It
- Google Sheets Limitations vs Excel: Key Differences
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Excel VBA Range of Worksheet Failed: Causes and FixesThe message Method 'Range' of object '_Worksheet' failed is usually Excel’s Run-time error 1004: VBA could not resolve…
- Delete Blank Rows in Excel VBA Safely and CorrectlyTo delete completely blank rows with VBA in Excel for Microsoft 365 on Windows, run a macro that…
- Excel VBA VLOOKUP: Examples, Errors, and AlternativesIn Excel VBA, use Application.VLookup(lookup_value, table_array, column_index, False) to find an exact match in the first column of…
- Rename a UserForm in Excel VBA Without Breaking ReferencesTo rename a UserForm in Excel VBA, open the Visual Basic Editor, select the form in Project Explorer,…
- Excel VBA: Export a Workbook to a New File FormatTo export an Excel workbook with VBA, use Workbook.SaveAs to save the open workbook in a different file…
- Using VBA to Sort Contracts in Excel: A Practical LessonTo sort a contract register by expiration date with VBA, put the records in one rectangular range with…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.