Hi, I use Excel 2010 andexample.xlsx cannot make my code working because of the so famous errore above. I was unable to find a solution reading previous posts, so hope anyone can help me.
I have several pivot tables (pt) in different worksheets (ws), and a list of items stored in an array I created. I've written a macro for setting ON all items in pt except those ones in the array (listOffnet within the code). Everything works properly.
Now, I would like to do the complementary action: setting OFF all items that are not in the array. Unfortunately, I get the error at line
Many thanks! This is my code:
Sub ptFilterOffnet()
Dim PvtTbl As PivotTable
Dim pvtItm As PivotItem
Dim pvtFld As String
Dim listItem As Variant
Dim listOffnet As Variant
Dim lastRow As Integer
Dim myws As String
pvtFld = "CATEGORY_DESCRIPTION"
myws = "GESTIONE_ADMIN"
resetSlicers 'function resetting all slicers connected to pivot tables (all items ON)
' Populate the array with some data in a specific range
lastRow = Sheets(myws).Cells(Rows.Count, 10).End(xlUp).Row
listOffnet = populateArray(myws, 3, lastRow, 10, 10)
' All OFF but items within listOffnet
For Each PvtTbl In Sheets("P1").PivotTables
For Each pvtItm In PvtTbl.PivotFields(pvtFld).PivotItems
For Each listItem In listOffnet
If pvtItm <> listItem Then
pvtItm.Visible = False
End If
Next
Next
Next
End Sub
Bookmarks