title: Refreshing queries with vba
body: <p>I have a worksheet with 5 <code>Access</code> Queries that I have pulled into Excel.  I need to make a VBA to cycle through the 5 tables and have them refresh every time it is ran. However, my code does not seem to execute and it just skips over the loop. Can someone point me in the right direction. Thanks!</p>
  
  <pre><code>Private Sub CommandButton1_Click()
      Application.ScreenUpdating = False
  
      UnlockSheets
  
      ' Update the raw data queries for needed information
      Worksheets("Data").Activate
          Range("A:AR").EntireColumn.Hidden = False
  
          Dim QT As QueryTables
          Dim ws As Worksheet
          Set ws = Worksheets("Data")
  
          For Each QT In ws.QueryTables
              QT.Refresh
          Next QT
          Application.StatusBar = False
  
          Range("A:AR").EntireColumn.Hidden = True
  
      ' Refresh the pivot tables in the worksheet "pivot"
      Worksheets("Pivot").Activate
          Dim pvtTbl As PivotTable
  
          For Each pvtTbl In ActiveSheet.PivotTables
              pvtTbl.RefreshTable
          Next
  
      ' Update the rank sheet with the needed information
      Worksheets("Rank").Activate
          ActiveSheet.Calculate
          ActiveSheet.EnableCalculations = True
          DoEvents
  
      LockSheets
  
      Application.ScreenUpdating = True
  
  End Sub
  </code></pre>