This is baffling us. I have a standard pivot table with a report filter on it that allows multiple selection of items. I can get the selected items in the report filter with:
Dim pi As PivotItem
For Each pi In PivotTables("MyPivot").PivotFields("MyField").PivotItems
If pi.Visible Then
Debug.Print pi.Value
End If
Next
Simple. My collegue has a standard pivot table with a report filter on it that allows multiple selection of items. He tries getting selected items in the report filter with the same code:
Dim pi As PivotItem
For Each pi In PivotTables("HisPivot").PivotFields("HisField").PivotItems
If pi.Visible Then
Debug.Print pi.Value
End If
Next
And gets a Type Mismatch error on pi.Visible
. We know that Visible
is a property in pi
, as after typing pi.
the intellisense appears with all the PivotItem
properties and methods (as you'd expect). We know that pi contains a valid PivotItem, as calling pi.Value
prints the value correctly (removing the If
/End If
statements to just let it print the value regardless will print every item in the list). There is nothing 'special' about his report filter - it isn't a calculated field or anything like that. Most other properties of PivotItem
also fail.
Does anyone know why PivotItem
would show this behaviour? The MSDN reference seems rather inadequate.