Hello, All.
I need some assistance. I have a macro that modifies my data query. Once the query is modified I need to refresh all my tables, query and all my pivot tables. I created a macro to refresh my data but I have to run the macro twice so the pivot tables can make the updated corrections.
How can I correct this code?
OR
How can I have the refresh macro run twice?
Any help would be greatly appreciated. Please see VBA code below:
Sub Refresh_Data()
'Refresh data source
ActiveWorkbook.RefreshAll
'Refresh Pivot Tables
Dim PT As PivotTable
Dim WS As Worksheet
For Each WS In ThisWorkbook.Worksheets
For Each PT In WS.PivotTables
PT.RefreshTable
Next PT
Next WS
'Refresh Worksheet in "EmpLoan PTable" - Worksheet is hidden
Worksheets("EmpLoan PTable").PivotTables("PivotTable1").RefreshTable
'Message Box
MsgBox "All Data Tables Refreshed"
End Sub
I need some assistance. I have a macro that modifies my data query. Once the query is modified I need to refresh all my tables, query and all my pivot tables. I created a macro to refresh my data but I have to run the macro twice so the pivot tables can make the updated corrections.
How can I correct this code?
OR
How can I have the refresh macro run twice?
Any help would be greatly appreciated. Please see VBA code below:
Sub Refresh_Data()
'Refresh data source
ActiveWorkbook.RefreshAll
'Refresh Pivot Tables
Dim PT As PivotTable
Dim WS As Worksheet
For Each WS In ThisWorkbook.Worksheets
For Each PT In WS.PivotTables
PT.RefreshTable
Next PT
Next WS
'Refresh Worksheet in "EmpLoan PTable" - Worksheet is hidden
Worksheets("EmpLoan PTable").PivotTables("PivotTable1").RefreshTable
'Message Box
MsgBox "All Data Tables Refreshed"
End Sub