Change PivotTable filter with cell reference

domtrump

Board Regular
Joined
Apr 1, 2010
Messages
245
I'm using the code below to change the Month number in all od the PowerPivot tables in my workbook. I'd like it to change from hard-coding the month in the VBA to get it to read the value of cell D5 on a worksheet called "Control" Can you tell me the proper syntax to do this? When I try to use a regular cell reference, nothing happens. Thanks.

Code:
Sub ChgMnth()
     Dim wks As Worksheet
     Dim pvt As PivotTable
     
     On Error Resume Next
     For Each wks In Worksheets
         For Each pvt In wks.PivotTables
             pvt.PivotFields("[TOPSLOT].[RMONTH].[RMONTH]").CurrentPageName = "[TOPSLOT].[RMONTH].&[5.]"
     
         Next pvt
     Next wks
     End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Why not use switch to slicer-control instead: You can use one slicer to filter all desired Pivot tables at once:

Add a slicer to a Pivot table. Then right click the slicer - choose "Report Connections" & click all other Pivot tables that should be controlled by this slicer as well.

So the only thing to do will be to click the new month once for the whole workbook.
 
Upvote 0

Forum statistics

Threads
1,224,115
Messages
6,176,467
Members
452,728
Latest member
mihael546

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