VBA Filter Pivot Table Question

gmazza76

Well-known Member
Joined
Mar 19, 2011
Messages
774
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

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Forum statistics

Threads
1,224,813
Messages
6,181,107
Members
453,021
Latest member
Justyna P

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