• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 414
  • Last Modified:

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
0
GPSPOW
Asked:
GPSPOW
  • 2
1 Solution
 
Martin LissRetired ProgrammerCommented:
Add Application.EnableEvents = False at the start and set it to True at the end.
0
 
GPSPOWAuthor Commented:
Thanks

glen
0
 
Martin LissRetired ProgrammerCommented:
You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2013
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now