title: Setting all Pivot Fields Visible = False using VBA?
body: <p>I am trying to set all items in a pivot table fields <code>visible = false</code>. E.g I have 5 divisions in each country called DivA, DivB, DivC, DivD and DivE. Now sometimes in my source data i have more or less than the above mentioned division so I want to turn all otions off under pivotfield"Division" and then make visible all the above mentioned divisions if they are there (sometimes there might be 3, 4 or all 5 divisions).</p>
  
  <p>I found a code online and trying to incorporate it but it keeps giving me error of setting "False = False".</p>
  
  <p>Any Help would be much appreciated!</p>
  
  <p>Please see my code below:</p>
  
  <pre><code>Sub test()
  '
  ' test Macro
  '
  
  
     With ActiveSheet.PivotTables("PivotTable3").PivotFields("Division")
  
      Dim Table As PivotTable
      Dim FoundCell As Object
      Dim All As Range
      Dim PvI As PivotItem
  
      Set All = Worksheets("Sheet1").Range("A7:AZ10000")
      Set Table = Worksheets("Sheet1").PivotTables("PivotTable3")
      For Each PvI In Table.PivotFields("Division").PivotItems
          Set FoundCell = All.Find(PvI.Name)
          If FoundCell &lt;&gt; "itemname" Then
              PvI.Visible = False
          End If
      Next
  
          .PivotItems("DivA").Visible = True
          .PivotItems("DivB").Visible = True
          .PivotItems("DivC").Visible = True
          .PivotItems("DivD").Visible = True
          .PivotItems("DivE").Visible = True
  
  
      End With
  End Sub
  </code></pre>