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

Sorting Data Containing Merged Cells

When formatting the layout of your worksheet, Excel allows you to easily merge adjacent cells together. This can cause ...

Discover More

Changing the Reference in a Named Range

Define a named range today and you may want to change the definition at some future point. It's rather easy to do, as ...

Discover More

Determining If a Number is Odd or Even

Need to know if a number in a macro is odd or even? It's easy to figure out with the simple calculation shown in this tip.

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (ribbon)

Stepping Through a Macro with a Worksheet Visible

When developing a macro, it is often necessary to step through the various code lines so you can see what is happening on ...

Discover More

Making a Macro Button Stay Put

Excel allows you to add buttons to your worksheet that can be used to trigger macros. If you don't want those buttons to ...

Discover More

Triggering an Event when a Worksheet is Deactivated

One way you can use macros in a workbook is to have them automatically triggered when certain events take place. Here's ...

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 1 + 1?

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.