Speeding up Excel macros usually involves switching to "ScreenUpdating = False" and "Calculation = xlCalculationManual" at the start of the code and restoring them at the end. This prevents Excel from redrawing the screen or recalculating formulas for every single cell change, which is the most common cause of sluggish automation.

What You'll Need

  • A computer running Windows or macOS with Microsoft Excel installed.
  • The Excel Developer tab enabled in the ribbon (this is required to view or edit VBA code).
  • A basic understanding of the Visual Basic for Applications (VBA) editor and how to insert a new module.

Step-by-Step

  1. Open the VBA Editor. Press Alt + F11 on your keyboard. This shortcut works in most versions of Excel (Windows and Mac) to open the Integrated Development Environment (IDE). If you are on a Mac, you may need to go to the top menu bar, choose Tools > Macro > Visual Basic Editor, or set a custom shortcut in Excel's Preferences > Keyboard & Mouse > Customize Shortcuts.
  2. Insert a new module. In the VBA Editor window, right-click on the name of your workbook in the "Project-VBAProject" pane on the left. Hover over Insert and select Module. This creates a blank sheet where you can paste your macro code.
  3. Locate your existing macro. If you already have a macro you want to speed up, click on the Module folder in the left pane to see the list of code modules. Double-click the module containing the code you wish to optimize. If you are writing a new one, paste your code into this module window.
  4. Apply the ScreenUpdating setting. Scroll to the very top of your code. You need to add a line of code that turns off screen updating. The standard syntax is:
    Application.ScreenUpdating = False
    This line must be placed at the very beginning of the macro, before any other actions are taken. It tells Excel to stop refreshing the window display while the macro runs.
  5. Apply the Calculation setting. Find the line in your code that begins with Application.Calculation. If this line is missing, add it immediately after the ScreenUpdating line. Set it to manual mode to prevent Excel from re-calculating formulas for every change:
    Application.Calculation = xlCalculationManual
    On a Mac, the syntax might be slightly different depending on the Excel version; it is often Application.Calculation = xlCalculationManual or Application.Calculation = -4135 (the manual constant).
  6. Run the optimized code. Press F5 on your keyboard to run the macro. You will notice the process feels significantly faster, especially if your macro manipulates thousands of cells. Excel will not redraw the window with every cell change, and formulas will not recalculate until you tell it to.
  7. Restore ScreenUpdating. At the very end of your macro, you must turn screen updating back on. If you forget this step, the Excel window will remain frozen and you will not be able to interact with the spreadsheet. Add this line before the macro ends:
    Application.ScreenUpdating = True
  8. Restore Calculation. Immediately after the ScreenUpdating = True line, add the following to restore automatic formula calculations:
    Application.Calculation = xlCalculationAutomatic
    This ensures that when the macro finishes, your data remains accurate and responsive.
  9. Test with a sample macro. To verify the changes, create a simple test macro that highlights a range of cells. Run it with the new settings and then run it without them (by commenting out the Application lines) to compare the speed. The difference will be most noticeable when the macro interacts with the user interface, such as changing cell colors or font sizes.

Common Mistakes

The most frequent error is failing to restore the settings at the end of the macro. If you set ScreenUpdating = False but do not set it back to True, the Excel window will stop responding to mouse clicks or keyboard input until you close and reopen the file. Another common mistake is not applying the Calculation = xlCalculationManual setting when the macro performs data manipulation that triggers dependent formulas. Without this, Excel will try to recalculate the entire workbook for every change, creating a bottleneck that negates the speed gains.

Tips

It is good practice to wrap your optimization code in an On Error GoTo statement. This ensures that if the macro crashes for any reason, the ScreenUpdating and Calculation lines will still execute, preventing your Excel window from becoming unresponsive. Additionally, consider using the Application.EnableEvents = False line at the beginning of your macro. This stops Excel from running any other macros that might be triggered by the changes your code makes, which can further improve performance.

Troubleshooting

If your macro runs slowly despite adding the ScreenUpdating = False line, the issue is likely not screen refreshing. The bottleneck is usually the Calculation setting. Ensure that your code is actually changing data in cells that contain formulas. If so, the Calculation = xlCalculationManual line is essential. If the window is frozen after running the macro, check the very last line of your code to ensure you have set Application.ScreenUpdating = True. If you cannot click anything in the Excel window, press Ctrl + Break (Windows) or Command + Period (Mac) to force-quit the running macro and restore the interface.

Frequently Asked Questions

Does turning off screen updating affect the final output?

No. Turning off screen updating only affects the visual feedback you see on the monitor. It does not change the actual data, formulas, or formatting stored in the workbook. The output will be identical; you will just see the results appear instantly rather than watching the process happen in real-time.

Why does my macro still run slowly on a Mac?

The syntax for turning off screen updating can vary between Windows and Mac versions of Excel. On a Mac, you may need to use Application.DisplayAlerts = False or rely on the specific menu path in the VBA editor. Also, Mac Excel is generally slower than Windows Excel, so performance gains will be noticeable but may not be as dramatic.

What does xlCalculationManual mean?

This setting tells Excel to stop automatically recalculating formulas. By default, Excel recalculates every time you type a number into a cell that is referenced by a formula. xlCalculationManual pauses this process, allowing your macro to change hundreds or thousands of cells without Excel pausing to update the math for each one.