DaBeau96
DaBeau96

Reputation: 548

How to Refresh a Pivot Table with VBA

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

Answers (1)

DaBeau96
DaBeau96

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

Related Questions