Skip to main content

Application.ScreenUpdating property

Table of contents
  1. Syntax
  2. Remarks
  3. Example

True if screen updating is turned on. Read/write Boolean.

Syntax

expression.ScreenUpdating

expression A variable that represents an Application object.

Remarks

Turn screen updating off to speed up your macro code. You won't be able to see what the macro is doing, but it will run faster.

Remember to set the ScreenUpdating property back to True when your macro ends.

Example

This example demonstrates how turning off screen updating can make your code run faster. The example hides every other column on ActiveSheet, while keeping track of the time it takes to do so. The first time the example hides the columns, screen updating is turned on; the second time, screen updating is turned off. When you run this example, you can compare the respective running times, which are displayed in the message box.

Sub ElapsedTime()
    Dim ElapsedTime(2), i As Integer, startTime As Date, stopTime As Date, c As Range
    Application.ScreenUpdating = True
    For i = 1 To 2
        If i = 2 Then Application.ScreenUpdating = False
        startTime = Time
        Worksheets.Add
        For Each c In ActiveSheet.Columns
           If c.Column Mod 2 = 0 Then
               c.hidden = True
           End If
        Next c
        stopTime = Time
        ElapsedTime(i) = (stopTime - startTime) * 24 * 60 * 60
    Next i
    Application.ScreenUpdating = True
    MsgBox "Elapsed time, screen updating on: " & ElapsedTime(1) & " sec." & Chr(13) & "Elapsed time, screen updating off: " & ElapsedTime(2) & " sec."
End Sub

Leave a comment

Your email address will not be published. Required fields are marked *

Format your code: <pre><code class="language-vba">place your code here</code></pre>