Cat On A Spreadsheet
You've probably run into this problem: your macro works—but it's slow. Maybe it takes 30 seconds to process a report that should take 3. The good news? VBA can be surprisingly fast, if you code with performance in mind.
This post covers real-world performance optimizations you can make to your VBA scripts today. Whether you're working with large data sets, iterative processes, or intensive formatting tasks, these tips will help you squeeze out the best possible speed from your VBA code.
Excel does a lot of visual and background work you usually don’t notice. During macro execution, you want to suppress all that overhead.
💡 Don’t forget to turn these back on at the end:
It would also be a good idea to use error handling to ensure these settings get reset, even if something crashes.
You’ve probably seen VBA code like this:
It works, but it’s horribly inefficient. Instead:
💡 Access ranges, worksheets, and cells directly. Every call to .Select or .Activate triggers UI updates and slows execution.
Reading or writing to Excel cells one at a time is extremely slow, especially with loops. Instead, load the whole range into an array:
This can improve performance immensely, especially when working with large data sets.
Nested For loops are often the first bottleneck in VBA code. Instead, use a Scripting.Dictionary for lookups and de-duplication.
Lookups in dictionaries are constant-time (O(1)), compared to O(n) or worse with loops.
Excel doesn't always clean up after you. Release objects when you're done:
Also consider:
This stops Excel from keeping the clipboard active after a .Copy command, which can interfere with user workflows and memory.
Each time you access something like Cells(i, j).Value, Excel re-evaluates the reference. Store it in a variable:
This is especially important inside tight loops. Of course, it's also recommended to define your variable of the appropriate type, we only sed Variant here for illustration purposes. Please don't make all your variables variants. Please.
Want to see what parts of your code are slowest? Use a simple timer to evaluate portions of your code:
🎯 Summary: Speed Up Your VBA Like a Pro
Turn off screen updates and auto calculation to avoid UI lag
Avoid .Select for faster and cleaner code
Use arrays for bulk processing to get a major speed boost
Use dictionaries to replace nested loops
Clean up memory and clipboard to prevent lag and crashes
Cache property values to avoid redundant operations
Cat On A Spreadsheet