Results 1 to 2 of 2

Thread: Pivot Table

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2005
    Posts
    22

    Pivot Table

    1. i created one PivotTable, in the RowAxis, i need the list to collapse.
    how to do that in VBA?

    2. For that particular RowAxis, I have 100 members.
    eg.
    Client Name
    A1
    A2
    A3
    .
    .
    .

    how ever, i only want to include certain clients. I know the standard code is
    .FieldSets("client name").Fields(0).IncludedMembers = Array("A1", "A2")

    but, i need to pass in the list of names from another table.
    so, for example, i have another recordset with the client names,
    A2,
    A3,
    A5...
    I need to pass each of these to be included in my RowAxis.
    how to do that?

  2. #2
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Pivot Table

    Loop through each of the items in the pivotfield and compare it to the list of customers for inclusion. If its in the list then show it, oterwise hide it. Here's some sample code, you will need to change the reference to the correct pivotfield and to your customer list.

    VB Code:
    1. Sub FilterPivot()
    2. Dim PvtFld As PivotField
    3. Dim PvtItem As PivotItem
    4. Dim CustomerRange As Range
    5. Dim ChkCount As Integer
    6.  
    7.    
    8.     Set PvtFld = Worksheets("PTable").PivotTables(1).PivotFields("client name")
    9.     Set CustomerRange = Worksheets("PTable").Range("f1:f5")
    10.    
    11.     For Each PvtItem In PvtFld.PivotItems
    12.         ChkCount = Application.WorksheetFunction.CountIf(CustomerRange, PvtItem.Name)
    13.         If ChkCount = 0 Then
    14.             PvtItem.Visible = False
    15.         Else
    16.             PvtItem.Visible = True
    17.         End If
    18.     Next PvtItem
    19.  
    20. Set PvtItem = Nothing
    21. Set PvtFld = Nothing
    22. End Sub
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

Posting Permissions

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



Click Here to Expand Forum to Full Width