Expert guide
Power Query vs VBA: Which Should You Use in Excel?
Power Query for data, VBA for actions, and both together for most real workbooks
Call us at +1 (385) 386-3860
Short answer: use Power Query to get, clean, reshape and combine data, because it is repeatable, macro-free and refreshes in one click. Use VBA to perform actions: format reports, save and email files, print, react to buttons and events, or drive Outlook and Word. Most robust workbooks use Power Query for the data pipeline and a little VBA (or Office Scripts) for output. We design that split in our Excel automation projects.
Ten years ago, almost every Excel automation was a macro. Today many of those macros are thousands of lines of VBA that copy, paste, delete blank rows and fix data types, all things Power Query does with a few recorded steps. The question is no longer "which is better" but "which part of this job belongs to which tool".
Task-by-Task Comparison
| Task | Power Query | VBA |
|---|---|---|
| Import CSV, Excel, database, web data | Excellent, many connectors | Possible, more code |
| Combine all files in a folder | Excellent (From Folder) | Good with a loop |
| Clean: trim, split, types, remove rows | Excellent, recorded steps | Tedious to write and maintain |
| Unpivot, group, merge (join) | Excellent | Hard |
| Format sheets, colours, layout | No | Yes |
| Save as PDF, save copies, email | No | Yes |
| Respond to buttons and events | No | Yes |
| Drive Outlook, Word, other apps | No | Yes (desktop) |
| Works where macros are blocked | Yes (.xlsx) | No |
| Refresh on a schedule in the cloud | Via Power BI or Power Automate scenarios | Not natively |
Why Power Query Wins for Data Preparation
Repeatable
Every step is recorded; next month you click Refresh.
Transparent
Applied Steps show exactly what happens to the data, in order.
Robust to size
Handles hundreds of thousands of rows without loops.
No macro security
Works in .xlsx files that IT policies allow everywhere.
Non-destructive
The source stays untouched; the output table is rebuilt each refresh.
Why VBA Still Matters
Producing outputs: formatted reports, one file per branch, PDFs.
Distribution: emailing workbooks or PDFs through Outlook.
User interaction: forms, buttons, validation on entry, prompts.
Working with other Office applications on the desktop.
Legacy processes that would be costly to rebuild and work fine.
The Hybrid Pattern
1. Power Query: import + clean + combine → tblClean (refreshable)
2. Formulas / PivotTables: calculations and summaries on tblClean
3. VBA (one short macro):
ThisWorkbook.RefreshAll
Application.CalculateUntilAsyncQueriesDone
' format, export PDFs, email
4. Optional: Power Automate / Office Scripts for scheduled cloud runsThe macro shrinks from hundreds of lines to a few dozen, and the fragile data-wrangling code disappears. When the source layout changes, you adjust a Power Query step instead of debugging a loop.
Sub RefreshAndPublish()
Application.ScreenUpdating = False
ThisWorkbook.RefreshAll
Application.CalculateUntilAsyncQueriesDone
ThisWorkbook.Worksheets("Report").ExportAsFixedFormat xlTypePDF, _
ThisWorkbook.Path & "\Weekly Report " & Format(Date, "yyyy-mm-dd") & ".pdf"
Application.ScreenUpdating = True
End SubMigrating an Old Macro to Power Query
Read the macro and list what it does to data (import, filter, delete rows, split columns, lookups).
Rebuild those steps in Power Query from the same source files.
Compare output row counts and totals with the macro's output for a few periods.
Keep only the output steps (formatting, saving, emailing) in VBA.
Document the query steps' purpose with clear step names.
AI assistants can explain the old macro and draft the M code; see writing Power Query M with AI and using AI with Excel VBA.
Where Office Scripts Fit
Office Scripts are a modern option for workbooks stored in OneDrive or SharePoint, especially when automation should run on a schedule through Power Automate without anyone opening Excel. They complement Power Query in the cloud the way VBA complements it on the desktop. A full comparison is in Office Scripts vs VBA.
Decision Guide
Is the task mostly about data coming in? Power Query.
Is the task mostly about doing something with the result? VBA (desktop) or Office Scripts (cloud).
Are macros blocked for some users? Push as much as possible into Power Query.
Must it run unattended on a schedule? Consider Power Automate with Office Scripts, or a server-side process.
Is it a one-off? Do whatever is fastest, then automate only if it repeats.
For many files in a folder, both approaches are shown in looping through files with VBA and Excel data consolidation.
FAQ
Power Query vs VBA FAQ
Choosing the right Excel automation tool