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

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Forum statistics

Threads
1,223,237
Messages
6,170,924
Members
452,366
Latest member
TePunaBloke

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