Screenupdating vba excel описание

Home / VBA / VBA ScreenUpdating | How to Turn it ON and OFF

What is VBA Screen Updating?

ScreenUpdating is a property in VBA that you can use to turn “ON” and “OFF” the screen updating while running the code. You can turn it off before running a code that makes your code run faster and then turn it on once the execution of the code completes. You can read and write this property.

By default, screen updating is “ON” in Excel. When you normally run a code it takes a lot of flickering if that code takes time, but if you turn OFF the screen updating it will take less time than normal to run.

Turn OFF Screen Updating in VBA

  1. First, type the keyword “Application”.
  2. After that, press a dot “.” to open the properties and methods list.
  3. Now, select “ScreenUpdating”.
  4. In the end, specify “False” to it.

Once you turn off screen updating, VBA will not turn it ON once the code is executed. So it’s always better to turn it off from your end. The code would be like something below.

Points to Consider

  • Make sure to have the screen updating “ON” when you are using a user form.
  • If you are debugging code, it is better to have a screen updating “ON” so that you can see all the activities as they are.

There’s More

VBA With Statement | VBA Wait and Sleep Commands | VBA Status Bar | VBA Random Number | Line Break in a VBA Code | VBA Immediate Window (Debug.Print) | VBA Concatenate | VBA Module | VBA Random Number

VBA Screen Updating is a property used to avoid or prevent distraction flashes while running the code and make it fast by turning off screen updating. We can turn off the screen updating by setting this property as “False.”

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 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.

Table of contents
  • Excel VBA Screen Updating
    • When to use Screen Updating Feature?
    • How to use Screen Updating Feature in VBA Code?
      • Example #1 – Turn Off Screen Updating
      • Example #2 –
    • Recommended Articles

VBA-Screen-Updating

You are free to use this image on your website, templates, etc, Please provide us with an attribution linkArticle Link to be Hyperlinked
For 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 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?

You can download this VBA ScreenUpdating Excel Template here – VBA ScreenUpdating Excel Template

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 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.

VBA Screen Update Example 1

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.

VBA Screen Update Example 1-1

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.

Example 1-2

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

Example 1-3

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

To stop screen updating, set the status to FALSE.

Example 1-4

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.

Code:

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

Recommended Articles

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 VBA
  • Use VBA Debug Print
  • Break For Loop in VBA
  • ThisWorkbook Property in VBA
  • VBA FreeFile

Return to VBA Code Examples

In this Article

  • Disable ScreenUpdating
  • Enable ScreenUpdating
  • VBA ScreenUpdating Example
  • ScreenUpdating Refresh
    • VBA Settings – Speed Up Code
  • VBA Coding Made Easy

As cool as it looks watching your VBA macro manipulate the screen, you can help your Macro run faster if you turn off (disable) ScreenUpdating.

Disable ScreenUpdating

1. To disable ScreenUpdating, At the beginning of your code put this line:

Application.ScreenUpdating = False

Enable ScreenUpdating

2. To re-enable ScreenUpdating, At the end of your code put this line:

Application.ScreenUpdating = True

VBA ScreenUpdating Example

Your procedure will then look like this:

Sub ScreenUpdating_Example()
    Application.ScreenUpdating = False

    'Do Something
    Range("a1").Copy Range("b1")
    Range("a2").Copy Range("b2")
    Range("a3").Copy Range("b3")


    Application.ScreenUpdating = True
End Sub

vba screen updating

ScreenUpdating Refresh

Disabling ScreenUpdating will make your VBA code run MUCH faster, but it will also make your work appear more professional. End-users typically don’t want to see the behind the scenes actions of your procedures (especially when the procedure runs slow). Also, you may not want end-users to see the behind the scenes functionality (ex. Hidden Worksheets). I recommend disabling (and re-enabling) ScreenUpdating in virtually all of your procedures.

However, there are some times when you want the screen to refresh. To refresh the screen, you will need to temporarily turn back on ScreenUpdating (there is no screen “refresh” command):

    Application.ScreenUpdating = True
    'Do Something
    Application.ScreenUpdating = False

VBA Settings – Speed Up Code

There are several other settings to play with to improve your code speed.

Disabling Automatic Calculations can make a HUGE difference in speed:

Application.Calculation = xlManual

Disabling the Status Bar will also make a small difference:

Application.DisplayStatusBar = False

If your workbook contains events you should usually disable events at the beginning of your procedure:

Application.EnableEvents = False

Last, your VBA code can be slowed down when Excel tries to re-calculate page breaks (Note: not all procedures will be impacted).  To disable displaying page breaks use this line of code:

ActiveSheet.DisplayPageBreaks = False

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro – A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users!

VBA Turn Off On ScreenUpdating

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro — A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users!
vba save as

Learn More!

Ok! This one is important.

Any good VBA procedure always has this line mentioned at the beginning.

Application.Screenupdating=FALSE

And before the end of the procedure you will see this line too.

Application.Screenupdating=TRUE

What is ScreenUpdating?
Screenupdating is the property of application objects in VBA. It can be set to TRUE or FALSE. It is like a switch, that can be turned On or Off.

And What Does it Do?
The first line speed ups the macro processing by stopping real time screen updating of Excel.

If you have a long macro that writes into different sheets, applies filters, removes filters, changes sheets, saves workbooks, etc. And if you haven’t turned off screen updates using the line Application.Screenupdating=FALSE, then you will see the flickering on screen. Each and every change done by macro in the workbook will be shown dynamically. This slows down the macro speed.

And If you have this line at the beginning of macro, excel will not reflect changes done by macro until screenupdating is turned on using the line Application.Screenupdating=TRUE.

If you want to speed up your macro, disable the screen update at the beginning of subroutine and enable the screen update before the end of subroutine.

Here’s one Example:

Sub Screencheck()
 Application.Screenupdating=FALSE 'Disabling the screen updating.
 Sheet1.Activate
 Range("A1").value ="Hi"
 Range("A2").value ="How are you?"
 Range("A3").value ="Exceltip is amazing, isn't it?"
 Sheet2.Activate
 Application.Screenupdating= TRUE 'Enabling the screen updating.
End Sub

When you run the above sub you will not see any screen flickering. You will see the final result of work done by this macro.

Important Notes:

Make sure that you enable the screen update before your procedure ends. If you don’t enable the screen update, you will not be able to see the work done by the macro.

Unable screen updating before every Exit Sub and End Sub command. It is common to forget enabling screen updates before Exit Sub. If you don’t do this, you may keep wondering why your code didn’t work. But in reality, it did. You just can’t see it.

That’s it. This is what Application.Screenupdating = False does in VBA. This one line of code changes a lot. It is the difference between mature programming and careless programming. If you want to speed up your macro, always use this line in your code. 

I hope this was helpful to you. If you have any doubts regarding this article or have any other Excel/VBA related questions, feel free to ask in the comments section below. I’ll be happy to help.

Related Articles:

What is the difference Between ByRef and ByVal Arguments? :This is an important VBA Question. The ByVal and ByRef are used to pass arguments differently. One lets the change be made in the original variable while the other does not alter the original variable.

How To Loop Through Sheets In Excel Using VBA : While automating the usual boring tasks of excel in VBA, you’ll get the need to loop through each sheet. Let’s start with an example. VBA Code to Loop in all sheets in Activeworkbook and print sheet Name

Events in Excel VBASometimes we want something to happen automatically when a certain event occurs. To do something when a specific event happens in Excel, we use Excel VBA event 

Popular Articles:

50 Excel Shortcuts to Increase Your Productivity | Get faster at your task. These 50 shortcuts will make you work even faster on Excel.

The VLOOKUP Function in Excel | This is one of the most used and popular functions of excel that is used to lookup value from different ranges and sheets.

 COUNTIF in Excel 2016 | Count values with conditions using this amazing function. You don’t need to filter your data to count specific values. Countif function is essential to prepare your dashboard.

How to Use SUMIF Function in Excel | This is another dashboard essential function. This helps you sum up values on specific conditions.

Понравилась статья? Поделить с друзьями:
  • Screenshot excel in word
  • Science word and definition
  • Screen of microsoft word
  • Science vocabulary word list
  • Screaming the word no