Turning off screen updating

When executing a macro, you can watch everything that occurs in the macro. Although this can be instructive, after getting the macro working properly, it's often annoying and can slow things down considerably. Fortunately, you can disable the screen updating that normally occurs when you execute a macro. To turn off screen updating, use the following statement:

Application.ScreenUpdating = False

If you want the user to see what's happening at any point during the macro, use the following statement to turn screen updating back on:

Application.ScreenUpdating = True

To demonstrate the difference in speed, execute this simple macro, which fills a range with numbers:

Sub

FillRange()

Dim r as Long, c As Integer

Dim Number as Long

Number = 0

For r = 1 To 50

For c = 1 To 50

Number = Number + 1

Cells(r, c).Value = Number

Next c

Next r

End

Sub

You see each value being entered into the cells. Now insert the following statement at the beginning of the procedure and execute it again:

Application.ScreenUpdating = False

The range is filled up much faster, and you don't see the end result until the macro is finished running.

0 0

Post a comment