Excel VBA Screen Flickering During Macro: How to Use ScreenUpdating Correctly
🔍 WiseChecker

Excel VBA Screen Flickering During Macro: How to Use ScreenUpdating Correctly

Your Excel screen flickers or flashes rapidly when a VBA macro runs. This visual distraction makes the macro appear slow and unprofessional. The cause is Excel redrawing the screen after every single change your code makes. This article explains how to use the ScreenUpdating property to eliminate flickering and speed up your macros.

Key Takeaways: Stop VBA Screen Flicker

  • Application.ScreenUpdating = False: Turns off screen redraw at the start of your macro to prevent flickering and improve performance.
  • Application.ScreenUpdating = True: Re-enables screen updates at the end of your macro to show the final result and restore normal Excel interaction.
  • Error handling with ScreenUpdating: Ensures screen updates are always turned back on, even if your macro encounters a runtime error and stops.

Why VBA Macros Cause Screen Flickering

Excel is designed to show you every change as it happens. When your VBA code runs, it might modify cells, format ranges, or insert charts. By default, Excel tries to display each of these actions immediately. This causes the application to constantly refresh the window, resulting in a flickering or flashing effect.

The ScreenUpdating property controls this behavior. When set to True, Excel updates the screen. When set to False, Excel pauses all visual updates. This allows your code to run in the background. The screen remains static until you turn updating back on. This not only stops the flicker but also makes your macro run faster because Excel is not wasting time drawing.

When to Turn ScreenUpdating Off

Use ScreenUpdating = False for any macro that performs multiple operations. This includes loops that process many rows, code that applies formatting to large areas, or scripts that move data between sheets. For very short macros that change only one cell, the benefit is minimal. The primary goal is to batch visual changes together.

Steps to Implement ScreenUpdating in Your Macros

The correct method involves turning the property off, running your core code, and then turning it back on. You must also include error handling to prevent the property from being left in the off state.

  1. Open the Visual Basic Editor
    Press Alt + F11 on your keyboard to open the VBA development environment.
  2. Insert the ScreenUpdating command
    At the very beginning of your macro procedure, before any other code, type Application.ScreenUpdating = False on its own line.
  3. Add your main macro code
    Write or paste the code that performs your tasks, such as copying data or formatting cells, below the ScreenUpdating line.
  4. Turn screen updating back on
    At the end of your macro, just before the End Sub statement, type Application.ScreenUpdating = True.

Adding Basic Error Handling

To make your macro robust, use a simple error handler. This ensures ScreenUpdating is always set to True, even if the code fails.

  1. Set up the error handler
    After the Application.ScreenUpdating = False line, add On Error GoTo ErrorHandler.
  2. Label the end of your main code
    After your main code and before the Application.ScreenUpdating = True line, add Exit Sub on its own line.
  3. Create the error handler label
    Below the Exit Sub line, add a new line with the label ErrorHandler:.
  4. Add the reset command in the handler
    On the line after the label, type Application.ScreenUpdating = True. Then add MsgBox "An error occurred: " & Err.Description to alert the user.

Common Mistakes and Limitations of ScreenUpdating

Macro Crashes and Leaves ScreenUpdating Off

If your macro hits an error and stops without turning ScreenUpdating back to True, Excel will seem frozen. You will not see any changes you make manually. To fix this, run a simple one-line macro from the Immediate Window. Press Ctrl + G in the VBA Editor, type Application.ScreenUpdating = True, and press Enter.

Screen Does Not Update at All After Macro Runs

This happens if you forget to set ScreenUpdating = True at the end of your macro. Double-check your code’s exit points. Every possible path through the macro, including any early exits within If statements, must lead to the command that turns updating back on. Using the error handling structure above prevents this.

Flickering Persists in UserForm Controls

The Application.ScreenUpdating property does not control the repaint of UserForm controls like ListBoxes or MultiPages. For these, you may need to use the UserForm.Hide and UserForm.Show methods or control specific properties like ListBox.Clear in a batch to minimize visual updates.

ScreenUpdating vs Other Performance Methods

Item Application.ScreenUpdating Application.Calculation Application.EnableEvents
Primary Purpose Controls visual screen refreshes Controls when formulas recalculate Prevents event procedures from running
Typical Setting Set to False at macro start Set to xlCalculationManual Set to False at macro start
Performance Gain Eliminates flicker, speeds up display operations Speeds up macros that write to many formula cells Speeds up macros that trigger Worksheet_Change events
Risk if Left Off Excel appears frozen, no visual updates Formulas show stale, incorrect results Macros or features that rely on events will not work
Reset Command Application.ScreenUpdating = True Application.Calculation = xlCalculationAutomatic Application.EnableEvents = True

You can now write VBA macros that run without distracting screen flicker. Start by adding Application.ScreenUpdating = False to your next code module. For further speed improvements, combine it with Application.Calculation = xlCalculationManual. Remember to always use an error handler to reset the ScreenUpdating property to True, guaranteeing Excel remains usable even after a macro error.