I need to change a filter in a PivotTable based on a ListBox with multiselect property = 1 - fmMultiSelectMulti, but when I run my VBA code items that are selected in the ListBox lose the selection.
Here is the code:
Private Sub BtnAtualizarLiberty_Click()
With Sheets("Liberty_Data").PivotTables("DinamicaLiberty1").PivotFields("RSCORE_CGV6")
.EnableMultiplePageItems = True
For Z = 1 To .PivotItems.Count
.PivotItems(Z).Visible = False
For r = 0 To ListRiscoScoreLiberty.ListCount - 1
If ListRiscoScoreLiberty.Selected(r) = True And ListRiscoScoreLiberty.List(r) = .PivotItems(Z).Value Then
.PivotItems(Z).Visible = True
End If
Next
Next
End With
End Sub
I've solved the problem. I was filling the listbox with a pivot table data and when I was changing the pivot fields filter at the any others pivot table, the listbox lost all the selected items.
So, now I'm filling the listbox 'manually', I've made a sheet called "Filters" and I've filled a column with all listbox row and it has solved the problem.
Sorry for the bad english.