title: Slow VBA when selecting visible pivot items from another table
body: <p>I have <strong>OLAP</strong> pivot tables with more than 10000 pivot items. When filtering this pivot table based on another table, it takes minutes, even after manual calculation.
  Can someone help me optimize this?</p>
  
  <pre><code>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) &gt; 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
  </code></pre>