VBA Filter Pivot Table Question

gmazza76

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

I have come across an issue with a piece of VB code Ihave been using to auto filter another pivot table based on a cell reference and I am a bit lost.
The working code below works in other files but fails on the "Set pvFld" with error "unable to get the PivotFields property of the PivotTable class

So i recorded a macro of me doing this manually (bottom code" and the code looks totally different. Is there away to write this so the cell value can be used?
This is the first time I have come across this error as when I record the original steps in a working file, it doesnt look like anything from the one below, the only difference the current pivottable has an added measure in it

Working code in another file
Code:
Sheets("Pivot").Select
    Range("H10").Select
        ActiveSheet.PivotTables("PivotTable1").ClearAllFilters
            Set pvFld = ActiveSheet.PivotTables("PivotTable1").PivotFields("Week No")
            strFilter = ActiveWorkbook.Sheets("Pivot").Range("B4").Value
            pvFld.CurrentPage = strFilter

recorded Macro
Code:
Range("Q14").Select
    ActiveWindow.ScrollColumn = 2
    ActiveWindow.ScrollColumn = 3
    ActiveWindow.ScrollColumn = 4
    ActiveWindow.ScrollColumn = 5
    ActiveWindow.ScrollColumn = 6
    ActiveWindow.ScrollColumn = 7
    ActiveWindow.ScrollColumn = 8
    ActiveWindow.ScrollColumn = 9
    ActiveWindow.ScrollColumn = 10
    ActiveWindow.ScrollColumn = 11
    ActiveWindow.ScrollColumn = 12
    ActiveSheet.PivotTables("PivotTable5").PivotFields( _
        "[Table_OldestCase].[Week No].[Week No]").ClearAllFilters
    ActiveSheet.PivotTables("PivotTable5").PivotFields( _
        "[Table_OldestCase].[Week No].[Week No]").CurrentPageName = _
        "[Table_OldestCase].[Week No].&[5]"

thanks in advance
Gavin
 

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,089
Messages
6,123,058
Members
449,091
Latest member
ikke

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