ISO Help: Pivot Tables & VBA coding....

JDM-LTCS

New Member
Joined
Sep 7, 2006
Messages
40
Thanks in advance, BTW! :)

----------------------------------------

Here's the code I'm trying to run:

WalkDate = Worksheets("Print Me!").Range("DateChoice").Text
' WalkDate is cell F3
'

ActiveSheet.PivotTables("PivotTable1").PivotFields("Date").PivotItems("Show All").Visible = False

Worksheets("Print Me!").PivotTables("PivotTable1").PivotFields("Date").PivotItems(WalkDate).Visible = True



What I'm wanting is for the Pivot Table to filter by no date fields and then filter only by the field set in cell F3 (WalkDate).


Does this make sense? I'm getting an error message stating "Run-time error '1004': Unable to get the PivotItems property of the PivotField class"


:oops:
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Hi JDM-LTCS

I cannot test your code it because I have xl2000 and "Show all" was introduced in xl2002, but ...

... I'm convinced that the rule that says that it's not allowed to hide all the items in a field is still valid in xl 2002/2003. At one item must be visible. So I think that

... .PivotItems("Show All").Visible = False

is not allowed.

You can make the WalkDate field visible and the hide all others.
Something like:

Code:
dim PI As PivotItem

...

With Worksheets("Print Me!").PivotTables("PivotTable1").PivotFields("Date")
    .PivotItems(WalkDate).Visible = True
    For Each PI In .PivotItems
        If PI.Name <> WalkDate Then PI.Visible = False
    Next
End With

Please test it.
PGC

EDIT: added declaration of PI
 
Upvote 0
This is the code I came up with. It seems to work like a charm. I'll plug your code in place of mine and see how it works when I get a free moment.


Thanks!! :)


-------------------------------


Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Dim WalkDate As Date


On Error Resume Next
For Each pt In ActiveSheet.PivotTables
For Each pf In pt.ColumnFields
pf.AutoSort xlManual, pf.SourceName
For Each pi In pf.PivotItems
If pi = WalkDate Then
pi.Visible = True
Else
pt.PivotFields("Date").PivotItems("(blank)").Visible = False
pi.Visible = False
End If
Next
Next
pf.AutoSort xlAscending, pf.SourceName
Next
 
Upvote 0

Forum statistics

Threads
1,214,972
Messages
6,122,530
Members
449,088
Latest member
RandomExceller01

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