Pivot Table Filter by VBA question

gmazza76

Well-known Member
Joined
Mar 19, 2011
Messages
767
Office Version
  1. 365
Platform
  1. Windows
Good afternoon,

I have a couple of tables I want to filter using VB instead of a slicer as the pivot table come from 2 different tables and I cant use 1 slicer to do both tables.
I have worked some code (example1 below) which works on all my pivot tables bar the final one I have created and I think the reason is because the final pivot table is doing a distinct count.
I am trying to filter based on a week Number ("B18")

Is there a way to adapt my code to do the second part or how would I amend my code to align the "&[3] to my Range("B18")
Or is there a better way to do this?

Code:
Example 1
Sheets("SheetName").Select
    Range("AJ2").Select
            Set pvFld = ActiveSheet.PivotTables("PivotTable37").PivotFields("Week No")
            strFilter = ActiveWorkbook.Sheets("SheetName").Range("B18").Value
            pvFld.CurrentPage = strFilter

Recorded Macro
ActiveSheet.PivotTables("PivotTable42").PivotFields( _
        "[CAllTypeAHT 1].[Week No].[Week No]").ClearAllFilters
    ActiveSheet.PivotTables("PivotTable42").PivotFields( _
        "[CAllTypeAHT 1].[Week No].[Week No]").CurrentPageName = _
        "[CAllTypeAHT 1].[Week No].&[3]"
thanks in advance
Gavin
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Forum statistics

Threads
1,214,918
Messages
6,122,257
Members
449,075
Latest member
staticfluids

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