Power Query vs VBA: which one should you use?
Both can automate Excel, but they solve different problems. Here's how I decide which to use on client projects.
Clients often ask me to "write a macro" for a job that Power Query would handle better, and occasionally the other way round. Both tools automate Excel, but they're built for different kinds of work. Picking the right one up front saves hours and gives you something far easier to maintain.
The short answer
Use Power Query when the job is about getting, cleaning and combining data. Use VBA when the job is about doing things in Excel: formatting, creating files, sending emails, or reacting to what a user clicks.
On many projects the best answer is both: Power Query prepares the data and a small macro handles the rest.
When Power Query wins
Power Query (Data → Get & Transform) is built into Excel 2016 and later, including Microsoft 365. It's ideal when:
- You import the same kind of file every week or month and do the same clean-up steps each time.
- You need to combine many files from a folder into one table.
- The data needs reshaping: unpivoting columns, splitting text, fixing dates, removing duplicates.
- You merge two lists on a common column, like a VLOOKUP across thousands of rows.
The big advantage is that every step is recorded. Next month you drop the new file in the folder and click Refresh All. No code, and anyone who knows Excel can open the query and see what it does.
When VBA wins
VBA is still the right tool when you need Excel to act:
- Creating one workbook or PDF per customer, region or salesperson.
- Formatting reports exactly the same way every time.
- Buttons, user forms and input validation for people entering data.
- Sending emails from Outlook with attachments.
- Working with older Excel versions where Power Query isn't available.
The trade-off is maintenance. Macros live in .xlsm files, can be blocked by security settings, and need someone who reads code when something changes.
A quick comparison
| Power Query | VBA | |
|---|---|---|
| Best for | Importing, cleaning, merging data | Actions, formatting, files, emails |
| Skills needed | Excel menus (M code optional) | Programming |
| Repeating the job | Click Refresh | Click a button or run the macro |
| Handles large data | Very well | Can be slow if not written carefully |
| Security prompts | None | Macros must be enabled |
A typical example
Imagine a business that receives 40 branch sales files every month, each with slightly different column names, and spends two days combining them by hand.
A Power Query can load every file in the folder, rename the columns to a standard set and append everything into one table. A short VBA macro then builds a formatted PDF summary for each branch. The monthly job drops from days to minutes.
Where to start
If you've never used Power Query, open a messy file, select the data and choose Data → From Table/Range. Try removing a column, trimming text and changing a data type, then close and load. You'll see how quickly the steps add up.
If your process is already complicated and you'd rather have it built for you, send me a message with a sample file.