I am trying to set all items in a pivot table fields visible = false. 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).
I found a code online and trying to incorporate it but it keeps giving me error of setting "False = False".
Any Help would be much appreciated!
Please see my code below:
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 <> "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