Written by Allen Wyatt (last updated December 12, 2020)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365
When Dave writes a macro that must process a lot of information in a For...Next loop, he always uses the status bar to indicate progress. Typically, he'll have a message displayed there such as "Processing row X of Y." When "Y" is a large value (the top end of the For...Next loop), Excel often stops updating the status bar and displays something like "Not Responding" in Excel's title bar. The macro is still running, though, and when it completes, Excel starts responding and everything works like it should. Dave wonders how he can make Excel stop behaving in this manner and, instead, display the status bar updates like he wants.
This behavior seems to occur when it appears to Windows that Excel has stopped responding. (It is Windows, after all, that is responsible for what appears in a program's title bar.) I was able to reproduce the behavior quite easily if I have multiple programs open in Windows and I click to another program window while Excel is chunking through a long macro. Essentially, if Excel is busy performing the macro or it cannot keep up in asking Windows to update the status bar, then it does, indeed appear like Excel has stopped responding.
There are two possible approaches that can be used. First, you could use the DoEvents command within the loop. Normally this is used to instruct the macro to pay attention to anything that is in the events queue, such as when someone presses the keyboard. It is equivalent to forcing Excel to "look up" from the macro on which it is working and to communicate with Windows. This would, necessarily, let Windows know that Excel really is responsive and allow the updates to the status bar to occur. You could even put the command right after updating the status bar:
Application.StatusBar = "Processing row " & X & " of " & Y DoEvents
The other thing to try is to simply not update the status bar as much. If the upper end of your loop is very large, then it might be better to calculate a percentage and update the status bar when some portion of the total is completed—perhaps every 5% or 10% of the total. This would mean the status bar only needs to be updated 10 or 20 times during the loop, rather than hundreds or thousands of times. This may mean that Windows can keep up with the requests to update the status bar and, as a bonus, your macro may run faster because it doesn't have to update the status bar as often.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13341) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365.
Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!
When you need to stop a macro while it is running, you normally press Ctrl+Break. What are you to do if the keypress ...
Discover MoreOne of the most common ways of creating macros is to use Excel's macro recorder. This tip shows how easy it is to use the ...
Discover MoreSometimes you receive a phone number that contains alphabetic characters and you need to convert it to a purely numeric ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2020-12-12 11:12:33
J. Woolley
My Excel Toolbox includes the freely available ProgressBar_Text and ProgressBar_Form procedures. ProgressBar_Text uses the status bar. ProgressBar_Form includes a user form. I like to use the latter with Lightbox_Initiate to obscure the Excel window while a long macro is running, followed by Lightbox_Terminate. See https://sites.google.com/view/MyExcelToolbox/
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments