Filter PT based on Cell Values

AboveBeyond

Board Regular
Joined
Aug 14, 2007
Messages
114
Hi, I have a VBA code that filters PT based on a the values of a specific cell. However, this only seems to work on non-SSAS connected data source. I believe the reason why this code doesn't work is because my data source is a SSAS PT, the field "Code" doesn't actually list the values until the expand "+" sign is clicked.

Is there a way to make the code work with a SSAS PT?


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Target.Address = Range("B2").Address Then Exit Sub
    Dim pt As PivotTable
    Dim ptItem As PivotItem
    
    On Error GoTo CleanUp
    Application.EnableEvents = False
    
    For Each pt In Worksheets("Sheet1").PivotTables
        
        With pt.PivotFields("Code")
            If .EnableMultiplePageItems = True Then
                .ClearAllFilters
            End If
            If LCase$(Target.Value) = "all" Then
               .ClearAllFilters
            Else
               Set ptItem = .PivotItems(Target.Value)
               If Not ptItem Is Nothing Then
                   .CurrentPage = Target.Value
               End If
            End If
        End With
    Next
CleanUp:
   Application.EnableEvents = True
End Sub
 
Last edited:

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Forum statistics

Threads
1,224,158
Messages
6,176,745
Members
452,741
Latest member
Muhammad Nasir Mahmood

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