Reputation: 548
I'm trying to figure out how to refresh a pivot table. I get an error message when it reaches pt.RefreshTable
and I've tried .RefreshTable
and .PivotCache.Refresh
and they both gave me error code 1004.
Sub RefreshAllPivotTables()
Dim pt As PivotTable
activateSheet ("Sheet2")
Set pt = ActiveSheet.PivotTables("PivotTable3")
pt.RefreshTable
End Sub
Sub activateSheet(sheetname As String)
Worksheets("Sheet2").Activate
End Sub
Upvotes: 1
Views: 11719
Reputation: 548
The solution to the question is to use .Update
instead of .RefreshTable
Sub RefreshAllPivotTables()
Dim pt As PivotTable
activateSheet ("Sheet2")
Set pt = ActiveSheet.PivotTables("PivotTable3")
pt.Update
End Sub
Upvotes: 3