VBA pivot filter with array value for multiple criteria

Joined
May 27, 2022
Messages
7
Office Version
  1. 365
  2. 2011
"i want to filter varray varilable items only but this code brings blanks"

Sub DuplicateValuesFromSelection()

Dim myRange As Range

Dim myCell As Range
Dim wb As Workbook
Dim ws As Worksheet

Set wb = ThisWorkbook
Set GL = wb.Sheets("GL Paste")
Set PT = wb.Sheets("Sheet1 PT")
Set RGL = wb.Sheets("RawGL PT")

Dim vArray As Variant
Dim i As Integer, j As Integer
Dim pvFld As PivotField
Set pvFld = ActiveSheet.PivotTables("PivotTable1").PivotFields("CTRL")

Yrow = PT.Range("y1")(Rows.Count, 1).End(xlUp).Row

vArray = PT.Range("Y1:Y" & Yrow)

pvFld.ClearAllFilters

With pvFld
For i = 1 To pvFld.PivotItems.Count
j = 1
Debug.Print pvFld.PivotItems.Count
Do While j <= UBound(vArray, 1) - LBound(vArray, 1) + 1
If pvFld.PivotItems(i).Name = vArray(j, 1) Then
pvFld.PivotItems(pvFld.PivotItems(i).Name).Visible = True
Exit Do
Else
On Error Resume Next
pvFld.PivotItems(pvFld.PivotItems(i).Name).Visible = False
End If
j = j + 1
Loop
Next i
End With

End Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top