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

RWayneHAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rgonzo1971Commented:
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
0
Rory ArchibaldCommented:
You'll have to error handle:
on Error resume next
set myItem = ActiveSheet.PivotTables("PivotTable4").PivotFields("Ship To Name")
        .PivotItems("Haworth Holland Customer CPU       ")
on error goto 0
If not myItem is nothing then myitem.visible = False

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RWayneHAuthor Commented:
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
0
Rory ArchibaldCommented:
It just clears the error handler - i.e. cancels the On Error Resume Next.
0
RWayneHAuthor Commented:
Thanks for the help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.