+ Reply to Thread
Results 1 to 5 of 5

Pivot table selection

  1. #1
    Registered User
    Join Date
    07-15-2008
    Location
    germany
    Posts
    56

    Pivot table selection

    Hi Experts,

    I am trying to unselect the pivot items and then select just one item with vba which equals one of my variable?

    Could you give me some advises regarding this issue. I appreciate your responses.

    i am using the following code which is not working
    PHP Code: 
    Sub test()


    Dim n As Integer
    Dim x 
    As Integer

    ActiveSheet.PivotTables("PivotTable5").PivotFields("xx").PivotItems.Count

    For 1 To n

    On Error Resume Next
    With thePT
    .PivotFields("xx")

    If 
    myvariable Then
    .PivotItems(x).Visible True
    Else
    .
    PivotItems(x).Visible False

    End 
    If
    DoEvents
    End With
    Next x
    End Sub 

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Pivot table selection

    try this,
    Please Login or Register  to view this content.
    If that fails then post information about the error raised.
    Better yet post example file.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    07-15-2008
    Location
    germany
    Posts
    56

    Re: Pivot table selection

    Thanks Andy, the code works perfectly.

  4. #4
    Registered User
    Join Date
    07-15-2008
    Location
    germany
    Posts
    56

    Re: Pivot table selection

    I am now able to apply the filter on a rowfield but when my variable changes then this code does not work. I have filtered the rowfield "name" by value "a". If I afterward want to filter this field by name "b", then I dont get the desired result. Any idea what is going on there?
    Here is the code

    I am attaching the file as well

    PHP Code: 
    Sub test()


    Dim n As Integer
    Dim x 
    As Integer

    Dim myvariable
    Dim thePT 
    As PivotTable

    Set thePT 
    ActiveSheet.PivotTables("PivotTable4")
    ActiveSheet.PivotTables("PivotTable4").PivotFields("name").PivotItems.Count

    myvariable 
    "a"

    For 1 To n

    With thePT
    .PivotFields("name")

    If .
    PivotItems(x).Name myvariable Then
    .PivotItems(x).Visible True
    Else
    .
    PivotItems(x).Visible False

    End 
    If

    End With
    Next x
    End Sub 
    Attached Files Attached Files

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Pivot table selection

    You can not make all the items invisible.

    So first go through a loop that makes all items visible.

    Please Login or Register  to view this content.

+ 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