No. Google Sheets cannot run VBA macros: VBA is Microsoft’s Visual Basic for Applications, built for Microsoft Office, while Sheets uses Google Apps Script for automation. You can often recreate a VBA task in Sheets, but you cannot simply paste or import the VBA code and expect it to work.
Why VBA Does Not Run in Google Sheets
VBA macros are designed to work with Microsoft Office applications and their object models. A macro might refer to an Excel worksheet, a workbook, a cell range, or a button using Excel-specific VBA objects and commands. Google Sheets is a different application with a different programming environment, so it does not understand those VBA instructions.
Changing a file’s extension or uploading an Excel workbook does not bridge that gap. A workbook saved as an Excel macro-enabled file, such as an XLSM file, can still contain VBA when handled by Excel, but Google Sheets does not execute that VBA. If you convert a workbook to Google Sheets format, do not assume the VBA code will be preserved in a usable form. Keep the original Excel file as a backup if its macros matter.
This is a compatibility issue, not a limitation of spreadsheets in general. Google Sheets can automate many tasks, but its built-in automation language and services are different from Excel’s.
What Google Sheets Uses Instead
Google Sheets uses Google Apps Script, a cloud-based scripting platform based on JavaScript. Apps Script provides services for working with Google products, including the Spreadsheet service for reading and changing spreadsheet data. It can also interact with other Google services, subject to authorization, service limits, and the permissions of the account running the script.
A Sheets script can do familiar automation work: fill cells, apply formatting, create a sheet, prepare a report, or add a custom menu. However, similar outcomes do not mean the code is interchangeable. VBA and Apps Script use different languages, libraries, object names, event systems, and ways of accessing files. A VBA statement such as one that refers to an Excel workbook object needs to be redesigned using the corresponding Sheets and Apps Script concepts.
Scripts can be attached to a particular spreadsheet, which is useful when the automation belongs with that file. Apps Script can also be created as a separate project for broader use. In either case, people who run a script may be asked to authorize the access it needs.
How to Record and Run a Sheets Macro
If your task consists mainly of actions you can perform in the Sheets interface, the macro recorder is a practical place to start. It records supported actions and creates an Apps Script function behind the scenes. The generated code can be inspected and edited in the Apps Script editor, so recording can provide a starting point rather than a finished solution.
- Open the spreadsheet in Google Sheets in a web browser.
- Choose Extensions > Macros > Record macro.
- Choose whether the macro should use absolute references or relative references, then perform the actions you want to record.
- Save the macro and give it a name. If offered, choose a keyboard shortcut for it.
- Run it later from Extensions > Macros. On its first run, Google may ask you to authorize the script.
Absolute references replay actions against the same cells, while relative references apply actions in relation to the current selection. For example, recording a formatting change with relative references can be more useful when you want to apply it to a selected row or range other than the one used during recording. Choose the reference style according to how the task will be repeated.
The recorder is best for straightforward, repeatable interface actions. It may not capture every kind of interaction or produce elegant code, and it cannot turn a sequence of clicks into a complex Excel-style application automatically. For conditions, loops, custom logic, or integrations, editing the generated Apps Script or writing a script directly may be necessary.
Rebuilding a VBA Macro in Apps Script
There is no one-click VBA-to-Apps-Script converter that makes arbitrary Excel macros run in Sheets. Rebuilding usually means understanding the macro’s purpose, then implementing that purpose with Sheets features and Apps Script. Start with the task the macro accomplishes rather than translating each VBA line literally.
For example, suppose an Excel macro copies a report range, formats the heading, and clears an input area. In Sheets, you could identify the source and destination ranges with the Spreadsheet service, copy or set values, apply formatting, and clear the appropriate cells. If the original macro also creates an Outlook email, reads a local file, or controls another desktop application, that part needs a different design; Apps Script runs in Google’s environment and does not control the Windows desktop in the same way as VBA.
A useful migration plan is:
- Document the outcome. List the inputs, outputs, formatting changes, and any decisions the VBA macro makes.
- Separate spreadsheet work from outside integrations. A cell update may translate conceptually; a call to an Office application or a local computer resource may not.
- Check the target data and layout. Excel and Sheets differ in some features and behavior, so verify named ranges, formulas, charts, and formatting in the converted file.
- Rebuild a small part first. Test the new script on a copy and compare its results with the original macro.
- Plan for authorization and sharing. Decide who will run the script and whether it needs access beyond the spreadsheet.
For a short macro, this may be a manageable rewrite. For a large VBA project with user forms, event-driven behavior, external connections, or extensive Excel-specific logic, migration can amount to a software redevelopment project. Estimate the work based on the macro’s dependencies, not just its line count.
What Usually Transfers and What Does Not
Spreadsheet content and automation are separate things. Values, many formulas, and much of a workbook’s visible layout may be brought into Sheets when you upload or convert an Excel file, but that does not make its VBA operational. Some Excel-only features or behaviors can also change during conversion, so inspect the spreadsheet itself rather than assuming that a successful upload means complete compatibility.
Simple jobs such as applying a standard format, copying a range, or clearing a set of cells are often reasonable candidates for a recorded macro or a short Apps Script. More complicated jobs need closer assessment. Common obstacles include macros that rely on Excel events, Windows file paths, ActiveX controls, UserForms, add-ins, or automation of other Office programs. A similar-looking feature in Sheets may work differently or have no direct equivalent.
One common misconception is that Google Sheets can execute a VBA macro if the workbook remains in XLSX or XLSM format. The file format does not change the scripting engine. If the macro must run as VBA, use a compatible version of Excel rather than relying on Sheets to execute it.
Choosing Between Google Sheets and Excel
Choose based on the workflow and the people who need to use it, not just on whether a spreadsheet has macros. Google Sheets is a natural fit when browser-based collaboration and Google Workspace integration are priorities, and the automation can be recreated in Apps Script. Excel desktop is generally the right choice when an existing VBA project is essential and depends on Excel-specific capabilities.
Excel for the web is not the same as Excel desktop for VBA: VBA macros cannot be created, run, or edited in Excel for the web. Microsoft offers Office Scripts for certain Excel web and Microsoft 365 workflows, but Office Scripts are a separate technology, not a way to run VBA in a browser. If choosing between Google Sheets and Excel, check the exact application, account plan, and automation requirements before migrating.
Consider these factors before deciding:
- Does the current process depend on VBA, Excel add-ins, forms, or other Office applications?
- Can the job be expressed as spreadsheet edits and Google service integrations?
- Do users need simultaneous browser collaboration, offline work, or desktop-only capabilities?
- Who will maintain the automation, and are they comfortable with Apps Script or VBA?
- What access permissions, organizational rules, and service limits apply?
Permissions, Reliability, and Limits
Apps Script is not simply a macro that runs without oversight. Depending on what it does, a script may request permission to read or change spreadsheet data or use other Google services. Users should review the requested access and run scripts only when they trust the spreadsheet and its owner. In an organization, administrators may also control which scripts or services are permitted.
Apps Script has quotas and execution limits, and these can vary by account type and service. A script designed for a small sheet may need changes to handle a large dataset efficiently. Automated triggers also need care: a simple trigger and an installable trigger do not have identical permissions or behavior, and some actions require explicit authorization. Consult Google’s current Apps Script documentation for the applicable limits before depending on a script for a critical or high-volume process.
For reliability, make a copy of important data before testing, limit the script to the ranges it needs, and test with ordinary and unusual inputs. If a script is shared with collaborators, explain how to run it and what permissions it requests. A macro that works for its creator may need additional setup or authorization for another user.
Frequently Asked Questions
Can I use VBA in Google Sheets?
No. Sheets does not run VBA. You can rewrite suitable automation in Apps Script, or keep using Excel if the existing VBA code must remain unchanged.
Can Google Sheets convert VBA to Apps Script?
No automatic conversion makes general VBA code ready to run as Apps Script. The macro’s purpose and dependencies need to be reviewed, and the required behavior must be rebuilt for Sheets.
Will an Excel macro run if I upload an XLSM file to Google Sheets?
No. Uploading or opening the file does not give Sheets the ability to execute VBA. Preserve the original macro-enabled workbook if you may need to run it in Excel.
How do I create a macro in Google Sheets?
In a browser, choose Extensions > Macros > Record macro, perform supported actions, and save. Sheets creates an Apps Script function that you can run from the Macros menu.
Is Apps Script the same as VBA?
No. Apps Script is based on JavaScript and is designed for Google services; VBA is Microsoft’s Office automation language. They can sometimes accomplish similar tasks, but their code and application interfaces differ.
Can Excel for the web run VBA macros?
No. VBA runs in desktop Excel, not Excel for the web. Office Scripts are a separate option for some web-based Excel workflows and do not execute existing VBA code.
Related
- How to Copy Excel Cells to Word Without Losing Format
- Copy a Word Document into Excel: Best Methods and Tips
- Copying Text from Excel to Word: Formatting, Links and Tables
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Excel VBA Open Workbook Dialog: A Practical How-ToTo display a workbook picker in Excel VBA, call Application.GetOpenFilename, check whether the user cancelled, and pass the…
- Excel VBA Copy and Paste a Range to Another WorkbookTo copy a range from one open Excel workbook to another with VBA, use sourceRange.Copy Destination:=targetSheet.Range("B2"), replacing the…
- Excel VBA Mid: How the Function WorksIn Excel VBA, Mid returns part of a string, starting at a position you specify; positions begin at…
- Excel VBA Button: Add, Assign, and Fix Macro ButtonsAn Excel VBA button is a clickable control that runs a macro in a workbook. In Excel for…
- VBA Range.Intersect: Find Overlapping CellsIn VBA, use Application.Intersect(range1, range2) to find the cells shared by two or more ranges. It returns a…
- Google Sheets Macros: How They Work and How to Use ThemYes. Google Sheets has macros: you can record a sequence of spreadsheet actions and replay it later, or…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.