PDA

View Full Version : Trying to deselect pivot items



casper2
09-02-2008, 05:00 AM
Hi,

I'm working on a macro which creates a pivot in a new worksheet, with the fields "klantnaam" and "industryclass" in the row, "regio" in the column and "total value" as data. This works fine.
Problem starts when I try to deselect all items in "industryclass" except for two. I know which two items should be visible, I do not know how many items should be hidden or which they are.

I have tried the following code:
Dim ptit As PivotItem
For Each Item In PT.PivotFields("IndustryClass").PivotItems
Set ptit = PT.PivotFields("IndustryClass").PivotItems(Item)
ptit.Visible = False
Next Item

With PT.PivotFields("IndustryClass")
.PivotItems("Item1").Visible = True
.PivotItems("Item2").Visible = True
End With

This gives a runtime error when the macro reaches 'set ptit....'
Hope anyone can help me out on this one.

Thanks
Casper