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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Forum statistics

Threads
1,215,187
Messages
6,123,540
Members
449,107
Latest member
caya

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