Solved

How to make a VBA pause until a Refresh has completed.

Posted on 2013-11-14
3
387 Views
Last Modified: 2013-11-14
The following code will go to a tab in a spreadsheet, refresh the data and then return to the Dashboard when the refresh is finished.

The problem I am having is that the cursor returns to the Dashboard before the Refresh is finished and the user thinks he can make another selection.  When another selection is made, he either gets a warning that the refresh is still running does he want to cancel or continue with the refresh.  Or sometimes he gets a Run Time Error.

What can I add below make it so that the cursor does not go back to the dashboard until the Refresh has completed?

If Range("R1") = "Update Master Patient List" Then
                             
             ActiveWorkbook.Sheets("MeditechData").Activate
             If Not ActiveSheet.AutoFilterMode Then
                 ActiveSheet.Range("A5").AutoFilter
             End If
             Range("C1").Select
             ActiveWorkbook.RefreshAll
             ActiveWorkbook.Sheets("Dashboard").Activate
             Range("B8").Select
         End If


Thanks

Glen
0
Comment
Question by:GPSPOW
  • 2
3 Comments
 
LVL 47

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 39650355
Add Application.EnableEvents = False at the start and set it to True at the end.
0
 

Author Closing Comment

by:GPSPOW
ID: 39650361
Thanks

glen
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 39650376
You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2013
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question