+ Reply to Thread
Results 1 to 5 of 5

Pivot Table VBA Question

Hybrid View

  1. #1
    Registered User
    Join Date
    01-02-2007
    Posts
    39

    Arrow Pivot Table VBA Question

    Hello,

    I'm trying to write VBA code to hide all fields of a pivot table except one. I don't know what all the fields will be, except for the one I want to remail visible. Here's what I have so far:

    Sub Macro1()
    Dim Region As String
    Region = Range("E16").Value
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Label")
    .PivotItems("*").Visible = False
    .PivotItems(Region).Visible = True
    End With
    End Sub

    Unfortunately, the code errors on the "*" wildcard. Any help on a workaround would be much appreciated! Thanks.

    Brad
    Bradley D. Clouser
    www.ExcelPro.org

  2. #2
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070
    Hi Brad,

    Take a look at the code Debra wrote ...
    http://www.contextures.com/xlPivot03.html
    HTH
    Carim


    Top Excel Links

  3. #3
    Registered User
    Join Date
    01-02-2007
    Posts
    39
    You're the MAN, Carim! Here's the code, if anyone else is interested...

    Sub Macro1()
    Dim Region As String
    Dim PI As PivotItem
    On Error Resume Next
    'Hide all pivot table items.
    For Each PI In ActiveSheet.PivotTables("PivotTable1").PivotFields("Label").PivotItems
    PI.Visible = False
    Next PI
    'Show the pivot table item you want.
    Region = Range("E16").Value
    ActiveSheet.PivotTables("PivotTable1").PivotFields("Label").PivotItems(Region).Visible = True
    End Sub

  4. #4
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070
    Glad you fixed your problem ...

    Thanks to Debra ...

  5. #5
    Registered User
    Join Date
    07-11-2005
    Posts
    38
    I have a question about that macro. When I tried using it, it hides all items in a pivot table EXCEPT the last item (I am assuming because you must be showing at least one item?). Is there a way around this?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1