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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

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