I have tried to use the code below to update a number of Pivot tables in a workbook.
However I get the error message "Reference is not valid" when the macro gets to the code "pt.refreshTable".
I have tried different statements but still not able to get past this error - any ideas out there?
Thanks for the help.
Cheers
Kym
Sub RefreshAllPivots()
Dim wks As Worksheet
Dim pt As PivotTable
With Application
.Calculation = xlAutomatic
End With
With Application
.Calculation = xlManual
End With
For Each wks In Worksheets
For Each pt In wks.PivotTables
pt.RefreshTable
Next pt
Next wks
With Application
.Calculation = xlAutomatic
End With
End Sub
However I get the error message "Reference is not valid" when the macro gets to the code "pt.refreshTable".
I have tried different statements but still not able to get past this error - any ideas out there?
Thanks for the help.
Cheers
Kym
Sub RefreshAllPivots()
Dim wks As Worksheet
Dim pt As PivotTable
With Application
.Calculation = xlAutomatic
End With
With Application
.Calculation = xlManual
End With
For Each wks In Worksheets
For Each pt In wks.PivotTables
pt.RefreshTable
Next pt
Next wks
With Application
.Calculation = xlAutomatic
End With
End Sub