Guide to Making Your Macro Run Faster and Better in Excel

Add to Favorites
Author:

This guide will show you 4 different ways to make your macros run faster and more efficiently in Excel.

There are 4 main things that you can do to each macro in order to have it run faster.

Sections:

ScreenUpdating

Calculation

Events

Alerts

All Together

Notes

ScreenUpdating

This is the number one way to speed up a macro.

ScreenUpdating controls if Excel will update the worksheet each time something is done within the worksheet.

If you leave this setting on, which is the default value, and you do something like run a loop on every row of data and do something with that data, then Excel will update the screen after every change; this really slows things down.

Turn this off:

Application.ScreenUpdating = False

Turn this on:

Application.ScreenUpdating = True

Read more about this in our tutorial on turning-off ScreenUpdating in Excel.

Calculation

If you have a large spreadsheet with complex formulas or formulas linked to separate workbooks, this can really slow down a macro.

Calculation in Excel refers to Excel recalculating all formulas and functions in a worksheet after each time that something is changed in that worksheet. With small worksheets and simple formulas, you wouldn't notice anything; however, large spreadsheets with complex formulas linked to other workbooks can take a long time to update and really slow down a macro.

Turn this off:

Application.Calculation = xlCalculationManual

Turn this on:

Application.Calculation = xlCalculationAutomatic

Read more about this in our tutorial on disabling Calculation in Excel.

Events

Events are things in Excel that can be set to trigger a macro to run. You can set an event to run a macro with a user enters data into a cell, selects a cell, moves between worksheets, or even when they close the workbook.

Events are triggered when a user performs a specific action and also when a macro performs that action. As such, when you run a macro, Events can lead to unpredictable results or just slow macros. You can, however, turn-off these Events for the duration of the macro.

Turn this off:

Application.EnableEvents = False

Turn this on:

Application.EnableEvents = True

Read more about this in our tutorial on turning off Events in Excel.

Alerts

Alerts are Excel windows that pop-up to "alert" you to something. This happens when, for instance, you try to close a workbook without saving and Excel stops you and shows you a window that asks if you would like to save it or not.

This kind of behavior is cumbersome when doing things like running a macro that needs to open and close a workbook. To get around this, you can turn these messages and alerts off so they won't appear.

Turn this off:

Application.DisplayAlerts = False

Turn this on:

Application.DisplayAlerts = True

Read more about this in our tutorial on turning off Alerts in Excel.

All Together

Many people simply combine all of the above lines of code in their macros so they don't have to worry about these speed and usability issues.

Here is an example of this:

Sub your_macro()

'Turn everything off
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
Application.DisplayAlerts = False

'Code to run here

'Turn everything back on
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
Application.DisplayAlerts = True

End Sub

3a851a8e7135483d7307470a4a2515fa.jpg

Notes

The links in each section above provide more information and examples and can help you better understand what is happening in the macro.

Download the sample file for this workbook to get the last example in Excel.


Downloadable Files: Excel File

Question? Ask it in our Excel Forum


Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons 50+ Hours of Instruction 200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Similar Content on TeachExcel
Disable Calculation of Cells when Running a Macro in Excel
Tutorial: How to stop formulas and functions from updating in Excel when running a macro. This can s...
The Running Turkey in Excel - Happy Thanksgiving :)
Tutorial: Learn how to make a turkey run across a worksheet in Excel every time someone goes to a w...
Wildcards in Excel
Tutorial: Wildcards are characters that allow you to make more robust functions, searches, and filt...
Run a Macro when a User Does Something in the Worksheet in Excel
Tutorial: How to run a macro when a user does something in the worksheet, everything from selecting ...
Vlookup Macro to Return All Matching Results from a Sheet in Excel
Macro: This Excel Macro works like a better Vlookup function because it returns ALL of the matchi...
List All Named Ranges in Excel - Displays the Name and Value for Every Named Range Within the Active Workbook in Excel
Macro: List all of the named ranges in a workbook in Excel and the corresponding values store...
Tutorial Details
Downloadable Files: Excel File
Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course