Changing Pivot table filters based on a value in another cell

Dokat

Active Member
Joined
Jan 19, 2015
Messages
304
Office Version
  1. 365
Hi,

I am trying to change pivot table geography field based on the selection in cell b4 in Summary tab. Its a drop down table. I am using below code however it is not working.

Can someone please help.

HTML:
Public Sub UpdatePivotFieldFromRange(RangeName As String, FieldName As String, _PivotTableName As String)

Dim rng As Range    Set rng = Application.Sheets("Summary").Range(B4)        Dim pt As PivotTable    Dim Sheet As Worksheet    For Each Sheet In Application.ActiveWorkbook.Worksheets        On Error Resume Next        Set pt = ThisWorkbook.Sheets("Source Data").PivotTables(PivotTable1)    Next    If pt Is Nothing Then GoTo Ex    On Error GoTo Ex        pt.ManualUpdate = True    Application.EnableEvents = False    Application.ScreenUpdating = False        Dim Field As PivotField    Set Field = pt.PivotFields(Geography)    Field.ClearAllFilters    Field.EnableItemSelection = False    SelectPivotItem Field, rng.Text    pt.RefreshTableEx:    pt.ManualUpdate = False    Application.EnableEvents = True    Application.ScreenUpdating = True    End Sub

Public Sub SelectPivotItem(Field As PivotField, ItemName As String)    Dim Item As PivotItem    For Each Item In Field.PivotItems        Item.Visible = (Item.Caption = ItemName)    NextEnd Sub
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Forum statistics

Threads
1,224,521
Messages
6,179,285
Members
452,902
Latest member
Knuddeluff

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