Excel VBA Screen Updating

We often feel the Excel screen going crazy while the Macro is running. We almost get frustrated by that. But, how do we deal with these situations and make the code run faster than the usual slow thing?

Screen Updating is something we can notice while the excel macroExcel MacroA macro in excel is a series of instructions in the form of code that helps automate manual tasks, thereby saving time. Excel executes those instructions in a step-by-step manner on the given data. For example, it can be used to automate repetitive tasks such as summation, cell formatting, information copying, etc. thereby rapidly replacing repetitious operations with a few clicks. read more is running. When the task is executing, we notice our screen updating the values until the Macro finishes its assigned task. As our screen flickers or refreshes, it leads to the slowdown of the Excel program and takes a longer time than usual to complete the task.

In VBA, we have a property called “ScreenUpdating,” we set this property to FALSE to eliminate the screen updating process while the code runs.

This article will say goodbye to watching on-screen action drama while the code is running. Instead, today you will make your code run faster and quicker than your usual time.

You are free to use this image on you website, templates, etc., Please provide us with an attribution linkHow to Provide Attribution?Article Link to be HyperlinkedFor eg:Source: VBA Screen Updating Property (wallstreetmojo.com)

When to use Screen Updating Feature?

Suppose you have any doubt about when to use this technique. Then, look into the below points.

  • Looping through a large number of cells.Sending emails from Excel VBASending Emails From Excel VBAWe can use VBA to automate our mailing feature in Excel to send emails to multiple users at once. To use Outlook features, we must first enable outlook scripting in VBA, and then use the application method.read more.Switching between Excel workbooks.Opening new workbooks.

How to use the Screen Updating Feature in VBA Code?

Example #1 – Turn Off Screen Updating

Look at the below code.

Code:

Sub Screen_Updating()

Dim RowCount As Long Dim ColumnCount As Long Dim MyNumber As Long

MyNumber = 0

For RowCount = 1 To 50

For ColumnCount = 1 To 50 MyNumber = MyNumber + 1 Cells(RowCount, ColumnCount).Select Cells(RowCount, ColumnCount).Value = MyNumber Next ColumnCount

Next RowCount

End Sub

The above has a nested VBA loopVBA LoopA VBA loop in excel is an instruction to run a code or repeat an action multiple times.read more to insert serial numbers from the first column to the 50th column and again to insert serial numbers starting from 51 from the second row to the 50th column.

Like this, it will insert until it reaches the 50th row.

While this code is running, you can notice your screen flickering. You cannot do anything apart from watching this crazy moment.

To avoid all of these, we can add Screen Updating to FALSE.

To access the Screen Updating feature, first, we need to access the Application object.

As we can see with the Application object, we have many properties and methods. So, select “Screen Updating” from the IntelliSense list.

Note: You must apply the Screen Updating feature immediately after declaring the variables.

After selecting the Screen Updating property, put an equal sign (=).

As we can see, there are two Boolean values: FALSE and TRUE.

To stop screen updating, set the status to FALSE.

As the Macro starts running first, it will update the screen, updating the status to FALSE, and proceed to the next line.

Since Macro executed Screen Updating to FALSE, it will not allow the screen to update while the code is executing its task.

Example #2 –

Always Set Screen Updating to TRUE at the End

We have seen many people set the Screen Updating to FALSE but forgot to set it back to TRUE at the end of the Macro.

Always set the Screen Updating back to TRUE at the end of the Macro.

Sub Screen_Updating()

Dim RowCount As Long Dim ColumnCount As Long Dim MyNumber As Long

Application.ScreenUpdating = False MyNumber = 0

For RowCount = 1 To 50

For ColumnCount = 1 To 50 MyNumber = MyNumber + 1 Cells(RowCount, ColumnCount).Select Cells(RowCount, ColumnCount).Value = MyNumber Next ColumnCount

Next RowCount Application.ScreenUpdating = True

End Sub

This article has been a guide to VBA Screen Updating. Here, we discuss how to use the Application.ScreenUpdating feature to make code run faster and quicker than your usual time, along with examples and a downloadable Excel template. Below are some useful Excel articles related to VBA: –

  • Solver Function in VBAUse VBA Debug PrintBreak For Loop in VBAThisWorkbook Property in VBAVBA FreeFile