从另一个表中选择可见枢轴项时,缓慢VBA

时间:2018-04-03 03:32:19

标签: vba performance filter olap visible

我有 OLAP 数据透视表,其中包含超过10000个数据透视表项。根据另一个表过滤此数据透视表时,即使在手动计算后也需要几分钟。 有人可以帮我优化吗?

Sub Pivot_Filter()

' Save the current state of Excel settings.
  screenUpdateState = Application.ScreenUpdating
  statusBarState = Application.DisplayStatusBar
  calcState = Application.Calculation
  eventsState = Application.EnableEvents
   ' Note: this is a sheet-level setting.
  displayPageBreakState = ActiveSheet.DisplayPageBreaks

 ' Turn off Excel functionality to improve performance.
  Application.ScreenUpdating = False
  Application.DisplayStatusBar = False
  Application.Calculation = xlCalculationManual
  Application.EnableEvents = False
 ' Note: this is a sheet-level setting.
  ActiveSheet.DisplayPageBreaks = False

   Dim PI As PivotItem

With ActiveSheet.PivotTables("PivotTable8").PivotFields("nomes")
   ManualUpdate = True
  .ClearAllFilters

    For Each PI In .PivotItems
        PI.Visible = WorksheetFunction.CountIf(Range("a2:a19"), PI.Name) > 0
    Next PI
    ManualUpdate = False
End With

' Restore Excel settings to original state.
 Application.ScreenUpdating = screenUpdateState
 Application.DisplayStatusBar = statusBarState
 Application.Calculation = calcState
 Application.EnableEvents = eventsState
' Note: this is a sheet-level setting
ActiveSheet.DisplayPageBreaks = displayPageBreaksState

End Sub

0 个答案:

没有答案