by Allen Wyatt
(last updated December 20, 2014)
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.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13341) applies to Microsoft Excel 2007, 2010, and 2013.
Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!
Using a macro to add worksheets to your workbook is easy. This tip provides two different methods you can use.Discover More
Place a cell reference in a macro, modify the structure of your worksheet, and you may soon find that the cell reference ...Discover More
There are a variety of ways that you might want to count the cells in your worksheet. One way is to figure out how many ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
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.