Excel 2007 Change Pivot Table (Select Multiple) with Macro

scottc_00

New Member
Joined
Feb 14, 2006
Messages
13
I need to select 2 items (months that are chosen by a user) in a pivot table. I can either put the Months as PageItems (Select Multiple) or FieldItems, either way I will get the results I need (when selected manually).
When choosing one item, no problem.
I use the code Sheets("Sheet1").Range("A3") = Sheets("Sheet2").Range("B4")
Where Sheet1!A3 is the PageItem for month
But to select 2 items is killing me.

If I put months as PageItems then I can't just use a simple replace I showed above. I somehow need to tell the pivot table to uncheck whatever is checked and then check
(make true) what the user has selected. When I tried to record a macro to
do this it listed every item in thePageField and set them to false and then set the selections to true. The problem with this is that I dont know what all the PageItems will be. I do know that the selections will be in the data.
So if I put Months in PageField I need one stmt to set "all" to false. Something like this:
PivotTables("PivotTable59").PivotFields("Month").PivotItems("(All)") = False
PivotTables("PivotTable59").PivotFields("Month").PivotItems("2/1/2010") = True
PivotTables("PivotTable59").PivotFields("Month").PivotItems("3/1/2010") = True

If I put Months as Field Items then I can use the direct replace shown above . . .
but instead of replacing the current item with the new item it just adds the date to what is already selected. If 2 were selected it will show 3 etc. so I still need to set all items to false and then set the items selected to True.

Thanks
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
How does the user select which months are to be shown?

To reset a filter on a Pivot Field you can use the ClearAllFilters method, like

Code:
PivotTables("PivotTable59").PivotFields("Month").ClearAllFilters
 
Upvote 0

Forum statistics

Threads
1,214,424
Messages
6,119,400
Members
448,893
Latest member
AtariBaby

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