?
Solved

Pivot Table, deselecting a field

Posted on 2014-08-29
5
Medium Priority
?
105 Views
Last Modified: 2014-09-10
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

0
Comment
Question by:RWayneH
  • 2
  • 2
5 Comments
 
LVL 54

Expert Comment

by:Rgonzo1971
ID: 40295294
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
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 2000 total points
ID: 40296642
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
 

Author Comment

by:RWayneH
ID: 40301812
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
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 40303443
It just clears the error handler - i.e. cancels the On Error Resume Next.
0
 

Author Closing Comment

by:RWayneH
ID: 40315186
Thanks for the help.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question