In Excel 2013 I have two pivot tables named "A" and "B". I need to refresh only one pivot table ("B") on sheet of my workbook for comparison.
I tried all below and it looks as if it should work as required - yet none of them will (i.e. both pivots will refresh after running any of the solutions). I tried changing Pivot Table Data options to all possible combinations with no change to outcome.
Sub refresh_pivot1()
'=================================================
Windows("File.xlsx").Activate
Sheets("Pivots").Select
'=================================================
ActiveSheet.PivotTables("B").PivotCache.Refresh
'=================================================
Worksheets("Pivots").PivotTables("B").RefreshTable
'==================================================
Dim PvtTbl As PivotTable
For Each PvtTbl In Worksheets("Pivots").PivotTables
If PvtTbl = "B" Then
PvtTbl.RefreshTable
End If
Next
'=================================================
Range("G3:K12").Calculate
'=================================================
Dim pt As PivotTable
Set pt = ActiveSheet.PivotTables("B")
pt.RefreshTable
'=================================================
End Sub
If both PivotTables are based on the same data source, then they share what's called a PivotCache. When you refresh a PivotTable, you are in fact refreshing the underlying PivotCache, and not an individual PivotTable. This means that when you refresh one PivotTable, you are actually refeshing *all' PivotTables that share that cache.
You need to tell Excel to assign your second PivotTable to a different Cache. See http://www.contextures.com/xlPivot11.html for code on how to do this (particularly the section "Create New Pivot Cache for Selected Pivot Table") or give Google a spin.