Pivot Filter Macro Help Requested

jmischel

New Member
Joined
Apr 8, 2008
Messages
30
I am trying to filter a field in a Pivot Table so that only the values 0 through 11 are visible. There may or may not be an instance of each value in each data set. If the value is present, I want it to be displayed. I have tried the following macro permutations but each has a problem:

ActiveSheet.PivotTables("Made2").PivotFields("Daysbetweenmakeandship"). _
ClearAllFilters

With ActiveSheet.PivotTables("Made2").PivotFields("Daysbetweenmakeandship")
.PivotItems("0").Visible = True
.PivotItems("1").Visible = True
.PivotItems("2").Visible = True
.PivotItems("3").Visible = True
.PivotItems("4").Visible = True
.PivotItems("5").Visible = True
.PivotItems("6").Visible = True
.PivotItems("7").Visible = True
.PivotItems("8").Visible = True
.PivotItems("9").Visible = True
.PivotItems("10").Visible = True
.PivotItems("11").Visible = True

End With

The problem with the above method is that if there is no "1", for instance, the macro errors out.

The 2nd method I've tried is this:

ActiveSheet.PivotTables("Made2").PivotFields("Daysbetweenmakeandship"). _
PivotFilters.Add Type:=xlCaptionIsBetween, Value1:="0", Value2:="11"

This one was recorded with the recorder on the developer tab. The problem with this one is that it is treating the data values as text instead of numbers. If I go into the PivotTable and use the "between" filter, the data filters correctly. But when I record that as a macro, the type+ is xlCaptionIsBetween and that doesn't work correctly.

Thanks for any help provided.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Try removing the quotation marks from around the values specified for args Value1 & Value2:
Code:
ActiveSheet.PivotTables("Made2").PivotFields("Daysbetweenmakeandship"). _
PivotFilters.Add Type:=xlCaptionIsBetween, Value1:=0, Value2:=11
 
Upvote 0
Doncha love it when recorded code don't work. :-D

:warning: Do be cognizant that the PivotFilter object is new @ 2007, so this code would crash if used on 2003 or lower. :warning:
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,331
Members
452,907
Latest member
Roland Deschain

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