How create button to refresh pivot table

Viewed 87

I would like create some button which will be refresh my pivot table after data changes. But my code remove all date and left empty template. This is my code. How i can resolve this

Sub RefreshAllPivots()

Dim pc as PivotCache
For each pc in thisWorkbook.PivotCaches

Pc.resfresh
Next pc
End sub
1 Answers

This should do it.

ThisWorkbook.RefreshAll

Or, loop through each one.

Dim Sheet as WorkSheet, Pivot as PivotTable
For Each Sheet in ThisWorkbook.WorkSheets
    For Each Pivot in Sheet.PivotTables
        Pivot.RefreshTable
        Pivot.Update
    Next
Next
Related