I have a report that picks up data from another excel file using Power Query. Within the report I have several pivot tables and calculations done etc.
When the source data changes, if I run Data -> Refresh All only data refreshes, the pivot tables don't.
If I click on a pivot table and then click Pivot Table -> Options -> Refresh All, all pivot tables refresh.
So I assume both steps are required to ensure the report is fully updated.
Now, I tried to put these steps into a VBA macro as shown below:-
However, only the data refreshes but the pivot tables don't refresh. If I run it again though everything refreshes.
Basically, if I run the above macro twice everything refreshes as expected.
One more thing that I noticed was that, if I step through the code instead of running it, it refreshes everything as expected in one execution.
What exactly could be causing the macro to not produce the expected results when running in one execution without stepping through the code?
When the source data changes, if I run Data -> Refresh All only data refreshes, the pivot tables don't.
If I click on a pivot table and then click Pivot Table -> Options -> Refresh All, all pivot tables refresh.
So I assume both steps are required to ensure the report is fully updated.
Now, I tried to put these steps into a VBA macro as shown below:-
Code:
Sub RefreshData()
Application.StatusBar = "Processing..."
'Refresh Data connection
ThisWorkbook.RefreshAll
'Refresh Pivot Cache
ThisWorkbook.Worksheets("Analysis View").PivotTables("Stage_Filter").PivotCache.Refresh
Application.StatusBar = False
End Sub
However, only the data refreshes but the pivot tables don't refresh. If I run it again though everything refreshes.
Basically, if I run the above macro twice everything refreshes as expected.
One more thing that I noticed was that, if I step through the code instead of running it, it refreshes everything as expected in one execution.
What exactly could be causing the macro to not produce the expected results when running in one execution without stepping through the code?