Hello,
I am trying to control the filters of a pivot table according to the .text of 2 combo boxes.
Everything works OK until I try to changing from visible to not visible certain items.
Here's my code:
filterName = Sheets("Reports").ComboBox1.Text
elementName = Sheets("Reports").ComboBox2.Text
If filterName <> "" Or elementName <> "" Then
With pt.PivotFields(filterName)
.AutoSort xlManual, .SourceName
Debug.Print "The source name of theb field is: " & .SourceName
For Each ptItem In pt.PivotFields(filterName).PivotItems
Debug.Print "Checking for " & ptItem.Name & "."
If ptItem.Name = elementName Then
ptItem.Visible = True
Debug.Print "Values for " & ptItem.Name & " are visible."
Else
ptItem.Visible = False
Debug.Print "Values for " & ptItem.Name & " are NOT visible."
End If
Next ptItem
.AutoSort xlAscending, .SourceName
End With
End If
I have read that it might be a bug, but it's been in forum posts from long ago, an it was solved with:
.AutoSort xlManual, .SourceName
Nevertheless, in my case it still displays the following error when I execute this code:
Error 1004: Unable to set the visible property of the PivotItem class
I am using MS Excel 2007. I would much appreciate your assistance.
Bookmarks