Avatar of RWayneH
RWayneH
Flag for United States of America asked on

Pivot Table, deselecting a field

The following code deselects it from a pivot table.  What happens if it is not there to deselect?  Is there a way to rewrite this so whether it is, or is not there is will deselect it?

    ActiveSheet.PivotTables("PivotTable4").PivotFields("Ship To Name").CurrentPage _
        = "(All)"
    With ActiveSheet.PivotTables("PivotTable4").PivotFields("Ship To Name")
        .PivotItems("Haworth Holland Customer CPU       ").Visible = False
    End With
    ActiveSheet.PivotTables("PivotTable4").PivotFields("Ship To Name"). _
        EnableMultiplePageItems = True

Open in new window

Microsoft Excel

Avatar of undefined
Last Comment
RWayneH

8/22/2022 - Mon
Rgonzo1971

I suppose you speak of this

With ActiveSheet.PivotTables("PivotTable4").PivotFields("Ship To Name")
        .PivotItems("Haworth Holland Customer CPU       ").Visible = False
    End With

then try

set myItem = ActiveSheet.PivotTables("PivotTable4").PivotFields("Ship To Name")
        .PivotItems("Haworth Holland Customer CPU       ")

If Not myItem Is Nothing Then myItem.Visible = False

Regards
ASKER CERTIFIED SOLUTION
Rory Archibald

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
RWayneH

ASKER
Rgonzo1971 suggestion did not work, unless he was referring to put it into the error handler?

Question on the:  On Error    what does the on error goto 0    do?   Is the zero no where? or a position?
I have used goto 100 or goto 200 but they have always referred to a different place in the procedure
Rory Archibald

It just clears the error handler - i.e. cancels the On Error Resume Next.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
RWayneH

ASKER
Thanks for the help.