Filtering pivot table on dynamic range of data in cells

Viper147

New Member
Joined
Apr 19, 2018
Messages
34
Good day all,
Trying to filter a pivot table based on a dynamic range of cells, but keep on getting the same result in that the table only gets filtered on the first value and the rest is ignored. This will ultimately form part of a loop but for now I just want to get the filtering to work. Any assistance will be appreciated.

VBA Code:
Option Explicit

Sub FilterPivotTable()
Dim filtvalues As Variant
Dim i As Integer, j As Integer
Dim pvt As PivotField
Dim pitm As PivotItem

filtvalues = Sheets("Mapping").Range("S7:W7")
Set pvt = Sheets("Recon By Business By Scheme").PivotTables("PivotTable28").PivotFields("Cognos code")
pvt.ClearAllFilters

For i = 1 To pvt.PivotItems.Count
    Set pitm = pvt.PivotItems(i)
    pitm.Visible = False
        For j = 1 To UBound(filtvalues, 1) - LBound(filtvalues, 1) + 1
            If pitm.Name = filtvalues(j, 1) Then
            pitm.Visible = True
            Exit For
            End If
        Next j
Next i

End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,224,822
Messages
6,181,164
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