Waiting for Update Completion

by Allen Wyatt
(last updated February 19, 2015)

It is not unusual to create a macro that loads data from an external source (such as a database query) and then processes that data. If you create such a macro, you may notice a slight problem—Excel doesn't wait for the data refresh to complete before it begins merrily chunking away on the code that follows.

The reason for this is simple—when you refresh information in a workbook from an external source (such as an Oracle database query), Excel won't wait around. This is contrasted with internal events in Excel, which can be easily waited upon. To overcome this difference, you need to change the way you write the macros. Essentially, you need to write two separate macros. The first macro basically initiates the refresh from the external source, and the second macro is executed once the refresh is completed.

How do you know when you can run the second macro? You could do it manually after visually inspecting the worksheet to make sure everything loaded, but that ties you up. Instead, you can tie a macro to the AfterRefresh event. This event is triggered when (as its name suggests) the refresh is complete. For more information on how to use this event in your programming, visit the Microsoft Knowledge Base articles at these addresses:

http://support.microsoft.com/kb/182735
http://support.microsoft.com/kb/213187

These Knowledge Base articles are for Excel 97 and Excel 2000, but the information they contain will also work with later versions of Excel.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2612) applies to Microsoft Excel 97, 2000, 2002, and 2003.

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

Embedding Your Phone Number in a Workbook

Want to provide a bit of contact information in a workbook? A great place to do it (out of sight, but not inaccessible) is in ...

Discover More

Searching for Borders

Want to find all the paragraphs in your document that have borders applied to them? The regular Find and Replace tool won't ...

Discover More

Resetting Ribbons

Word allows you to customize the program's ribbon tabs so they more closely match the way you want to work. At some point, ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (menu)

Getting Rid of the "Enable Macros" Notice

Do you get tired of the dialog box that says "do you want to enable macros" that is displayed when you open a workbook. You ...

Discover More

Stepping Through a Non-Contiguous Range of Cells

Using macros to step through each cell in a selection is a common occurrence. What if that selected range is made up of ...

Discover More

Creating Add-Ins

Want to create your own add-in? Excel makes it easy to do. Here are all the steps you need.

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}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 8Mpixels. 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 three more than 5?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon 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.