【发布时间】:2015-02-13 15:37:40
【问题描述】:
我有一个数据透视表,我正在尝试根据数组中的值选择某些数据透视项目。我需要这个过程更快,所以我尝试使用Application.Calculation = xlCalculationManual 和PivotTables.ManualUpdate = True,但似乎都不起作用;每次更改数据透视表时,数据透视表仍会重新计算。
我可以采取不同的措施来防止 Excel 每次都重新计算吗? 或者有没有办法一次(而不是单独)取消选择所有项目以加快处理速度?
这是我的代码:
Application.Calculation = xlCalculationManual
'code to fill array with list of companies goes here
Dim PT As Excel.PivotTable
Set PT = Sheets("LE Pivot Table").PivotTables("PivotTable1")
Sheets("LE Pivot Table").PivotTables("PivotTable1").ManualUpdate = True
Dim pivItem As PivotItem
'compare pivot items to array.
'If pivot item matches an element of the array, make it visible=true,
'otherwise, make it visible=false
For Each pivItem In PT.PivotFields("company").PivotItems
pivItem.Visible = False 'initially make item unchecked
For Each company In ArrayOfCompanies()
If pivItem.Value = company Then
pivItem.Visible = True
End If
Next company
Next pivItem
【问题讨论】:
-
尝试只计算公式(pivItem.Formula)然后计算。我有同样的问题,功能非常慢,所以我无法解决。
-
您只需要数据透视表中的值吗?你能做一个
.PasteSpecial xlPasteValues然后做你的查找数组吗? -
哪个版本的 Excel 以及数据透视表中的数据透视字段在哪里? (顺便说一句,你真的应该在
pivItem.Visible = True行之后有一个Exit For) -
-我正在研究 pivItem.Formula 部分。 -我需要数据透视表中的值根据数组中的值进行更改。用户选择他想查看的公司,宏用这些选择填充数组,然后根据数组更新数据透视表 - 我使用的是 Excel 2010。数据透视字段位于行标签部分非常感谢您的帮助和回应!
标签: vba excel pivot-table pivotitem