Link to home
Start Free TrialLog in
Avatar of RWayneH
RWayneHFlag 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

Avatar of Rgonzo1971
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
Avatar of Rory Archibald
Rory Archibald
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 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
It just clears the error handler - i.e. cancels the On Error Resume Next.
Avatar of RWayneH

ASKER

Thanks for the help.