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
 

Yard

Well-known Member
Joined
Nov 5, 2008
Messages
1,928
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
 

Forum statistics

Threads
1,081,415
Messages
5,358,533
Members
400,502
Latest member
price83

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top