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

Finding and Replacing in Text Boxes

Finding and replacing information in a worksheet is easy. Finding and replacing in other objects (such as text boxes or chart ...

Discover More

Disabling a Function Key

Function keys are used to perform common tasks in Excel. If you want to disable one of the function keys, it's rather easy to ...

Discover More

Accurate Font Sizes

Need to use some bizarre font size in your worksheet? Not a problem, provided it is a full or half point size.

Discover More

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!

More ExcelTips (menu)

Running Macros in the Background

Want to run a macro in Excel, but not sure if doing so will tie up your computer? Here's how macro processing really happens.

Discover More

Changing Macro Cell References Based on Edits

Place a cell reference in a macro, modify the structure of your worksheet, and you may soon find that the cell reference in ...

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
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. 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 seven minus 1?

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.