I want to start off this post by thanking everyone who sent in their examples in response to my January request.
In this post I’m going to share with you the most important performance tips I know about.There are tons of sites, pages, and people who are experts as well on this subject, have performed their own tests, and shared their results and ideas.If you think I missed an important concept for how to optimize Excel VBA performance, or if you’ve got a valuable comment or link to share, please feel free to post here so everyone can benefit. Turn Off Everything But the Essentials While Your Code is Running This optimization explicitly turns off Excel functionality you don’t need to happen (over and over and over) while your code runs.Note that in the code sample below we grab the current state of these properties, turn them off, and then restore them at the end of code execution. Display Page Breaks = False ‘note this is a sheet-level setting ‘: This setting tells Excel to not redraw the screen while False.One reason this helps is that if you’re updating (via VBA) several different ranges with new values, or copy / pasting from several ranges to create a consolidated table of data, you likely do not want to have Excel taking time and resources to recalculate formulas, display paste progress, or even redraw the grid, especially after every single operation (even more so if your code uses loops). The benefit here is that you probably don’t need Excel using up resources trying to draw the screen since it’s changing faster than the user can perceive.Just one recalculation and one redraw at the end of your code execution is enough to get the workbook current with all your changes. Enable Events display Page Break State = Active Sheet. Since it requires lots of resources to draw the screen so frequently, just turn off drawing the screen until the end of your code execution.
Here’s some sample code that shows how and what to shut off while your code runs. Display Page Breaks ‘note this is a sheet-level setting ‘turn off some Excel functionality so your code runs faster Application. Be sure to turn it back on right before your code ends.
Doing this should help improve the performance of your code: ‘Get current state of various Excel settings; put this at the beginning of your code screen Update State = Application. : This setting tells Excel to stop showing status while False.
For example, if you use VBA to copy/paste a range, while the paste is completing Excel will show the progress of that operation on the status bar.
Turning off screen updating is separate from turning off the status bar display so that you can disable screen updating but still provide feedback to the user, if desired.
Again, turn it back on right before your code ends execution.
: This setting allows you to programmatically set Excel’s calculation mode.