简体   繁体   English

仅刷新单个数据透视表

[英]Refreshing single PivotTable only

In Excel 2013 I have two pivot tables named "A" and "B". 在Excel 2013中,我有两个名为“A”和“B”的数据透视表。 I need to refresh only one pivot table ("B") on sheet of my workbook for comparison. 我需要在工作簿的工作表上只刷新一个数据透视表(“B”)以进行比较。

I tried all below and it looks as if it should work as required - yet none of them will (ie 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. 您需要告诉Excel将第二个数据透视表分配给不同的缓存。 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. 有关如何执行此操作的代码,请参阅http://www.contextures.com/xlPivot11.html (特别是“为选定的数据透视表创建新的数据透视表”一节)或给Google一个旋转。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM