I have a worksheet linked to external data that refreshes periodicaly throughout the day. Linked to the worksheet is a number of pivot tables. I haven't linked the pivots to the external data as the data needs a number of formulas to get other pivot values.
On running the code below the worksheet is update and it looks like the pivots are refreshed but it seems the pivots are refreshed before the external data is fully updated. If I manually refresh the pivots after the code refresh the pivots change.
I tried adding a 2 min wait before running the cache refresh but doesn't make any difference.
I can see the world icon rotating on the status bar - the pivot refresh needs to happen after that as stopped. The refresh all method is meant to refresh all external data ranges and pivots but doesn't seem to.
Any ideas?
Sub Refresher()
Dim WrkSheet As Worksheet
Dim Pvttable As PivotTable
Set WrkSheet = Worksheets("Last Month Pivots")
Application.StatusBar = "Getting Data Please Wait"
ThisWorkbook.RefreshAll
For Each Pvttable In WrkSheet.PivotTables
Pvttable.PivotCache.Refresh
Next
Application.StatusBar = False
Worksheets("Last 30 Days Dashboard").Range("O3") = "Last Data Refresh " & Format(Now(), "d-mmm-yy hh:mm")
End Sub
On running the code below the worksheet is update and it looks like the pivots are refreshed but it seems the pivots are refreshed before the external data is fully updated. If I manually refresh the pivots after the code refresh the pivots change.
I tried adding a 2 min wait before running the cache refresh but doesn't make any difference.
I can see the world icon rotating on the status bar - the pivot refresh needs to happen after that as stopped. The refresh all method is meant to refresh all external data ranges and pivots but doesn't seem to.
Any ideas?
Sub Refresher()
Dim WrkSheet As Worksheet
Dim Pvttable As PivotTable
Set WrkSheet = Worksheets("Last Month Pivots")
Application.StatusBar = "Getting Data Please Wait"
ThisWorkbook.RefreshAll
For Each Pvttable In WrkSheet.PivotTables
Pvttable.PivotCache.Refresh
Next
Application.StatusBar = False
Worksheets("Last 30 Days Dashboard").Range("O3") = "Last Data Refresh " & Format(Now(), "d-mmm-yy hh:mm")
End Sub