+ Reply to Thread
Results 1 to 5 of 5

Check/unCheck PivotItems from another sheets column

Hybrid View

  1. #1
    Registered User
    Join Date
    11-16-2009
    Location
    USA
    MS-Off Ver
    Office 2003, on WinXp SP3
    Posts
    3

    Question Check/unCheck PivotItems from another sheets column

    Hello everyone I’m new to the forum and need some help. Let me open with the fact that I have limited skills in the programming department so thanks in advance for your support.

    I have three sheets. One is data, one is a pivot table and one is the filter data which will have serial numbers I want to see in my pivot table “data, output, & filter”. My goal is to use a column of cells in “filter” sheet to hide and un-hide pivot items in the first column of “output”. The column is SERIAL_NUM.

    The PT comes from a table of test records with 70 columns and 15k rows ['CAL.DBF(2009-11-04)'!$A$1:$BS$15000]. My PT is setup but I have to manually uncheck "Show All" and search for and check-off 200 serial numbers in column 1 of the PT [SERIAL_NUM]. Can I execute a macro which allows me to select from a list or range cells I specify (like A2 to A201 or A2:A62)?
    I need to uncheck everything, and then check 'PivotItems Visible = True' to make items from my list visible. This would hide 14,000 plus records in the column. I only need to do this for one PT field “SERIAL_NUM” and manually check/uncheck the other field items as needed.

    It looks like I need a conditional statement and a loop but I’m not sure how to do this.

    Does this make sense? Thanks for any input!
    Final Impact

  2. #2
    Registered User
    Join Date
    11-16-2009
    Location
    USA
    MS-Off Ver
    Office 2003, on WinXp SP3
    Posts
    3
    Question: Do I need to count the records in the table to toggle each one from : PivotItems("16679").Visible = True (to False?) OR is there a global means of unchecking pivotitems for 15K records? Recording a macro doesn't help. If I need to count them, it looks like the pivot cache would give the answer.

    I saw this user defined function which is helpful but I'm not sure how to convert it from "Function" to something useful. Any hints?

    "=GetRecords(A3)" {this is a user defined function for the spreadsheet}
    'place this in the active PT on the active sheet.
    
    
    Function GetRecords(rngPT As Range) As Long
       Dim pt As PivotTable
       Set pt = rngPT.PivotTable
       GetRecords = ActiveWorkbook _
         .PivotCaches(pt.CacheIndex).RecordCount
    End Function
    With the above infomation I could to a For statement to toggle .Visible = false

    Any hints?

    Thanks
    FI
    Last edited by Final Impact; 11-17-2009 at 02:42 PM. Reason: Warning

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

    Re: Check/unCheck PivotItems from another sheets column

    You should be able to loop through the pivotfields items, although if you have 15K unique items it may have problems.

    Can you post a small sample file, say 4 columns, 100 records and 3 filter records. Set the PT up with the required filtering manually applied.
    Cheers
    Andy
    www.andypope.info

  4. #4
    Registered User
    Join Date
    11-16-2009
    Location
    USA
    MS-Off Ver
    Office 2003, on WinXp SP3
    Posts
    3

    Re: Check/unCheck PivotItems from another sheets column

    Andy,
    Here is the raw data, two pt's and the list.

    Cal.dbf is the data.
    Slot By Month is the first cut of SERIAL_NUM to use in the next PT filter.
    SN Retest is the second PT where the Serial_Num is from the above step is entered into the filter after Select none is applied.

    I know I can base one PT on another but I must to do this manually and keep them seperate as shown here.

    Problems I can anticipate:
    refresh issues, errors for missing records, and things of that nature.

    Thanks for looking.
    Any help is appreciated!
    Final Impact

    ALL - the file is clean and free of know viruses. It was safe when it left.
    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,481

    Re: Check/unCheck PivotItems from another sheets column

    With code, which is very slow.
    I named the range of Filter ID's, H5:H21, as FAILED

    Function CheckValue(Value As Long, DataTable As Range) As Boolean
        On Error Resume Next
        CheckValue = (Application.WorksheetFunction.Match(Value, DataTable, 0) > 0)
        Exit Function
    End Function
    
    Sub FilterPTItems()
    
        Dim rngFailed As Range
        Dim pvtTable As PivotTable
        Dim pvtField As PivotField
        Dim pvtItem As PivotItem
        Dim blnShow As Boolean
        
        Set rngFailed = ThisWorkbook.Names("FAILED").RefersToRange
        Set pvtTable = ThisWorkbook.Worksheets("SN Retest").PivotTables(1)
        Set pvtField = pvtTable.PivotFields("Serial_num")
        
        Application.ScreenUpdating = False
        On Error Resume Next
        For Each pvtItem In pvtField.PivotItems
            pvtItem.Visible = CheckValue(CLng(pvtItem.Value), rngFailed)
        Next
        Application.ScreenUpdating = True
    End Sub
    A quicker approach is to add a field to your pivot chart data source and use that as the page field.

    I added a new field, called SERIAL_FILTER, with the following formula.
    =MATCH(A2,FAILED,0)>0

    Update the data source to include the new field and then used as the Page field showing TRUE.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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