{"id":9490,"date":"2022-04-29T11:52:01","date_gmt":"2022-04-29T11:52:01","guid":{"rendered":"https:\/\/officetuts.net\/excel\/?p=9490"},"modified":"2024-02-19T15:00:25","modified_gmt":"2024-02-19T15:00:25","slug":"turn-screen-updating-on-and-off-in-vba","status":"publish","type":"post","link":"https:\/\/officetuts.net\/excel\/vba\/turn-screen-updating-on-and-off-in-vba\/","title":{"rendered":"How to Turn Screen Updating On and Off in VBA"},"content":{"rendered":"\n

If you ever worked with VBA, you could probably be in a situation where your code is not as fast as you would want it to be. There are a couple of things that you can do to speed it up a little bit.<\/p>\n\n\n\n

In the example below, we will show how to speed up the code by turning the screen updating off in VBA.<\/strong><\/p>\n\n\n\n

Turn Screen Updating On and Off<\/h2>\n\n\n\n

Screen updating can be turned on or off through the VBA module. In simple terms, it has to be done at the application level.  We are going to use the following sentence:<\/p>\n\n\n\n

Application.ScreenUpdating = False (turning it off)\nApplication.ScreenUpdating = True (turning it on)<\/code><\/pre>\n\n\n\n

We will show its importance in one example. To do this, we need to open the Excel file, click on ALT + F11,<\/strong> and then right-click on the left window that appears, go to Insert >> Module:<\/strong><\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

When a new window appears in which we should write our code, we can start with it.<\/p>\n\n\n\n

This is what our code will look like:<\/p>\n\n\n\n

Sub AddingSheets()\n    Application.ScreenUpdating = FALSE\n    Dim sTime As Single, ElapsedTime As Single, sec As Single\n    sTime = Timer        'find out starting time\n    Worksheets.Add after:=Sheets(Sheets.Count)\n    ElapsedTime = Timer - sTime        'Save the elapsed time to ElapsedTime variable\n    'Extract seconds\n    sec = ElapsedTime\n    Debug.Print \"Time passed: \" & sec & \" sec\"\nEnd Sub<\/code><\/pre>\n\n\n\n

This is what our code looks like in the module itself:<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

This code first declares variables that we going to use, and then it sets variable sTime<\/strong> to be equal to the Timer:<\/strong><\/p>\n\n\n\n

Dim sTime As Single, ElapsedTime As Single, sec As Single\nsTime = Timer<\/code><\/pre>\n\n\n\n

Then we need concrete action. In our case, our action is to add a worksheet at the end of our workbooks, i.e. after the end of our sheets list.<\/p>\n\n\n\n

After that, we calculate ElapsedTime<\/strong> as the difference between the Timer and start time<\/strong>, and we store that number in the ElapsedTime variable<\/strong>.<\/p>\n\n\n\n

Worksheets.Add after:=Sheets(Sheets.Count)\nElapsedTime = Timer - sTime<\/code><\/pre>\n\n\n\n

For the next part, we want to extract seconds from our variable, so we do just that by setting the sec variable<\/strong> to be equal to ElapsedTime<\/strong>.<\/p>\n\n\n\n

sec = ElapsedTime<\/code><\/pre>\n\n\n\n

Now, for the final part, we will use the Debug.Print option<\/strong> to show us the time that it took for our sheet to be created:<\/a><\/p>\n\n\n\n

Debug.Print \"Time passed: \" & sec & \" sec\"<\/code><\/pre>\n\n\n\n

Now, Debug.Print<\/strong> option is great for us because it will give us the information that we need (the time spent creating a sheet) without having to store this information in a variable or without showing it in a message box.<\/p>\n\n\n\n

To use Debug.Print<\/strong> option, we need to turn on the Immediate window<\/strong>. We will do it by going to the View tab<\/strong> in our Module<\/strong> and choosing the Immediate window, or simply clicking CTRL + G<\/strong>:<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

With this window visible, we will execute our code (by going into the code and clicking F5)<\/strong> and we will see the message in our Immediate window:<\/p>\n\n\n\n

Time passed: 0.015625 seconds<\/em><\/p>\n\n\n\n

Or in our Module:<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

We will also have a new sheet created, as defined in our code.<\/p>\n\n\n\n

To speed up the execution of our code, we will simply add an Application.ScreenUpdating = False<\/strong> above our code and beneath the part where we defined subroutine (Sub….):<\/strong><\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

Now, when we execute our code again, these are the results that we will get:<\/p>\n\n\n\n

Time passed: 0.0078125 seconds<\/p>\n\n\n\n

Or in the module:<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

To turn on the screen updating again, we just need to insert:<\/p>\n\n\n\n

Application.ScreenUpdating = True<\/code><\/pre>\n\n\n\n

You will notice that our code is executed so much faster without screen updating. Although it is a matter of seconds in our case that is only because we defined such a small portion of code (sheet to be added) to be executed. Just imagine how much time can you spare when it comes to more complex code.<\/p>\n","protected":false},"excerpt":{"rendered":"

If you ever worked with VBA, you could probably be in a situation where your code is not as fast as you would…<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"yoast_head":"\nHow to Turn Screen Updating On and Off in VBA<\/title>\n<meta name=\"description\" content=\"How to speed up VBA code by turning off screen updating. Learn how to do it through Application.ScreenUpdating in Excel. #VBA #Excel\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/officetuts.net\/excel\/vba\/turn-screen-updating-on-and-off-in-vba\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Turn Screen Updating On and Off in VBA\" \/>\n<meta property=\"og:description\" content=\"How to speed up VBA code by turning off screen updating. Learn how to do it through Application.ScreenUpdating in Excel. #VBA #Excel\" \/>\n<meta property=\"og:url\" content=\"https:\/\/officetuts.net\/excel\/vba\/turn-screen-updating-on-and-off-in-vba\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-04-29T11:52:01+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-02-19T15:00:25+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2022\/04\/inserting-module-1.png\" \/>\n<meta name=\"author\" content=\"Harun Spahic\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Harun Spahic\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/turn-screen-updating-on-and-off-in-vba\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/turn-screen-updating-on-and-off-in-vba\/\"},\"author\":{\"name\":\"Harun Spahic\",\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/694491c70f776081acdac4ae41f222a2\"},\"headline\":\"How to Turn Screen Updating On and Off in VBA\",\"datePublished\":\"2022-04-29T11:52:01+00:00\",\"dateModified\":\"2024-02-19T15:00:25+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/turn-screen-updating-on-and-off-in-vba\/\"},\"wordCount\":559,\"publisher\":{\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42\"},\"image\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/turn-screen-updating-on-and-off-in-vba\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2022\/04\/inserting-module-1.png\",\"articleSection\":[\"vba\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/turn-screen-updating-on-and-off-in-vba\/\",\"url\":\"https:\/\/officetuts.net\/excel\/vba\/turn-screen-updating-on-and-off-in-vba\/\",\"name\":\"How to Turn Screen Updating On and Off in VBA\",\"isPartOf\":{\"@id\":\"https:\/\/officetuts.net\/excel\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/turn-screen-updating-on-and-off-in-vba\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/turn-screen-updating-on-and-off-in-vba\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2022\/04\/inserting-module-1.png\",\"datePublished\":\"2022-04-29T11:52:01+00:00\",\"dateModified\":\"2024-02-19T15:00:25+00:00\",\"description\":\"How to speed up VBA code by turning off screen updating. Learn how to do it through Application.ScreenUpdating in Excel. #VBA #Excel\",\"breadcrumb\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/turn-screen-updating-on-and-off-in-vba\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/officetuts.net\/excel\/vba\/turn-screen-updating-on-and-off-in-vba\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/turn-screen-updating-on-and-off-in-vba\/#primaryimage\",\"url\":\"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2022\/04\/inserting-module-1.png\",\"contentUrl\":\"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2022\/04\/inserting-module-1.png\",\"width\":500,\"height\":467},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/turn-screen-updating-on-and-off-in-vba\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/officetuts.net\/excel\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Turn Screen Updating On and Off in VBA\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/officetuts.net\/excel\/#website\",\"url\":\"https:\/\/officetuts.net\/excel\/\",\"name\":\"\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/officetuts.net\/excel\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42\",\"name\":\"Tomasz Decker\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/18cbe22837193574870ae40ba56bf712?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/18cbe22837193574870ae40ba56bf712?s=96&d=mm&r=g\",\"caption\":\"Tomasz Decker\"},\"logo\":{\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/image\/\"},\"description\":\"Spreadsheet and Python enthusiast.\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/694491c70f776081acdac4ae41f222a2\",\"name\":\"Harun Spahic\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/b7b887a2249679182be5550a4421a7a9?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/b7b887a2249679182be5550a4421a7a9?s=96&d=mm&r=g\",\"caption\":\"Harun Spahic\"},\"sameAs\":[\"http:\/\/human.bsru.ac.th\/\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Turn Screen Updating On and Off in VBA","description":"How to speed up VBA code by turning off screen updating. Learn how to do it through Application.ScreenUpdating in Excel. #VBA #Excel","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/officetuts.net\/excel\/vba\/turn-screen-updating-on-and-off-in-vba\/","og_locale":"en_US","og_type":"article","og_title":"How to Turn Screen Updating On and Off in VBA","og_description":"How to speed up VBA code by turning off screen updating. Learn how to do it through Application.ScreenUpdating in Excel. #VBA #Excel","og_url":"https:\/\/officetuts.net\/excel\/vba\/turn-screen-updating-on-and-off-in-vba\/","article_published_time":"2022-04-29T11:52:01+00:00","article_modified_time":"2024-02-19T15:00:25+00:00","og_image":[{"url":"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2022\/04\/inserting-module-1.png"}],"author":"Harun Spahic","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Harun Spahic","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/officetuts.net\/excel\/vba\/turn-screen-updating-on-and-off-in-vba\/#article","isPartOf":{"@id":"https:\/\/officetuts.net\/excel\/vba\/turn-screen-updating-on-and-off-in-vba\/"},"author":{"name":"Harun Spahic","@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/694491c70f776081acdac4ae41f222a2"},"headline":"How to Turn Screen Updating On and Off in VBA","datePublished":"2022-04-29T11:52:01+00:00","dateModified":"2024-02-19T15:00:25+00:00","mainEntityOfPage":{"@id":"https:\/\/officetuts.net\/excel\/vba\/turn-screen-updating-on-and-off-in-vba\/"},"wordCount":559,"publisher":{"@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42"},"image":{"@id":"https:\/\/officetuts.net\/excel\/vba\/turn-screen-updating-on-and-off-in-vba\/#primaryimage"},"thumbnailUrl":"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2022\/04\/inserting-module-1.png","articleSection":["vba"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/officetuts.net\/excel\/vba\/turn-screen-updating-on-and-off-in-vba\/","url":"https:\/\/officetuts.net\/excel\/vba\/turn-screen-updating-on-and-off-in-vba\/","name":"How to Turn Screen Updating On and Off in VBA","isPartOf":{"@id":"https:\/\/officetuts.net\/excel\/#website"},"primaryImageOfPage":{"@id":"https:\/\/officetuts.net\/excel\/vba\/turn-screen-updating-on-and-off-in-vba\/#primaryimage"},"image":{"@id":"https:\/\/officetuts.net\/excel\/vba\/turn-screen-updating-on-and-off-in-vba\/#primaryimage"},"thumbnailUrl":"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2022\/04\/inserting-module-1.png","datePublished":"2022-04-29T11:52:01+00:00","dateModified":"2024-02-19T15:00:25+00:00","description":"How to speed up VBA code by turning off screen updating. Learn how to do it through Application.ScreenUpdating in Excel. #VBA #Excel","breadcrumb":{"@id":"https:\/\/officetuts.net\/excel\/vba\/turn-screen-updating-on-and-off-in-vba\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/officetuts.net\/excel\/vba\/turn-screen-updating-on-and-off-in-vba\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/officetuts.net\/excel\/vba\/turn-screen-updating-on-and-off-in-vba\/#primaryimage","url":"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2022\/04\/inserting-module-1.png","contentUrl":"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2022\/04\/inserting-module-1.png","width":500,"height":467},{"@type":"BreadcrumbList","@id":"https:\/\/officetuts.net\/excel\/vba\/turn-screen-updating-on-and-off-in-vba\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/officetuts.net\/excel\/"},{"@type":"ListItem","position":2,"name":"How to Turn Screen Updating On and Off in VBA"}]},{"@type":"WebSite","@id":"https:\/\/officetuts.net\/excel\/#website","url":"https:\/\/officetuts.net\/excel\/","name":"","description":"","publisher":{"@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/officetuts.net\/excel\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42","name":"Tomasz Decker","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/18cbe22837193574870ae40ba56bf712?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/18cbe22837193574870ae40ba56bf712?s=96&d=mm&r=g","caption":"Tomasz Decker"},"logo":{"@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/image\/"},"description":"Spreadsheet and Python enthusiast."},{"@type":"Person","@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/694491c70f776081acdac4ae41f222a2","name":"Harun Spahic","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/b7b887a2249679182be5550a4421a7a9?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b7b887a2249679182be5550a4421a7a9?s=96&d=mm&r=g","caption":"Harun Spahic"},"sameAs":["http:\/\/human.bsru.ac.th\/"]}]}},"_links":{"self":[{"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/posts\/9490"}],"collection":[{"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/comments?post=9490"}],"version-history":[{"count":4,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/posts\/9490\/revisions"}],"predecessor-version":[{"id":14675,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/posts\/9490\/revisions\/14675"}],"wp:attachment":[{"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/media?parent=9490"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/categories?post=9490"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/tags?post=9490"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}