Link to home
Start Free TrialLog in
Avatar of GPSPOW
GPSPOWFlag for United States of America

asked on

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

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
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of GPSPOW

ASKER

Thanks

glen
You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2013