Macro, while Running, Stops Excel from Responding

Written by Allen Wyatt (last updated December 12, 2020)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


1

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:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

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.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Understanding MRU Files

Don't you love all the acronyms used in computer terminology? One such acronym—pertinent to Word users—is ...

Discover More

Correctly Repeated Words

There are times when you need to repeat a word in a document, but doing so triggers an "error reaction" from Word's ...

Discover More

Deleting VBA Code in a Copied Worksheet

VBA makes it easy to copy a worksheet from the current workbook into a brand-new workbook. You may want to delete some ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

More ExcelTips (ribbon)

Copying Worksheet Code Automatically

When creating a workbook to be used by others, you may want any worksheets they add to the workbook to contain some ...

Discover More

Deleting Blank Rows

Got some pesky blank rows in your data that you want to get rid of? This tip provides a wide variety of methods you can ...

Discover More

Setting Column Width in a Macro

Does your macro need to change the width of some columns in a worksheet? Here's how to do it.

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 8 - 5?

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/


This Site

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.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.