title: Speed up pivot table filtering VBA code
body: <p>I have a pivot table with a pivot field and contain many items.
  I've VBA code logic to decide if the pivot value should be visible or not.
  The problem is excel recalculates pivot table for each field shown or hidden which makes it very slow.
  I would like something where it recalculates only once, after all the values are set.
  I tried using Application.Calculation = xlCalculationManual but it didnt help.</p>
  
  <p>vba code that I am using is something like this</p>
  
  <pre><code>For i = 1 To oPivotField.PivotItems.Count
      If (oPivotField.PivotItems(i).Name = "TestCondition") Then
          oPivotField.PivotItems(i).Visible = True   'Recalulates pivot table
      Else
          oPivotField.PivotItems(i).Visible = False 'Recalulates pivot table
      End If
  Next
  </code></pre>
  
  <p>I am to do this manually by uncheck the "show all" box and re-check for the fields I want visible. This cause Excel to recalculate once and show only the pivot items I want visible.
  I would like to do same thing via VBA code.</p>
  
  <p>I even tried using</p>
  
  <pre><code>Application.ScreenUpdating = False
  Application.DisplayAlerts = False
  </code></pre>
  
  <p>but didn't work.</p>