+ Reply to Thread
Results 1 to 2 of 2

Filter a Pivot table based on cell in another workbook

Hybrid View

nicknorth34 Filter a Pivot table based on... 07-14-2011, 02:35 PM
Mordred Re: Filter a Pivot table... 07-14-2011, 02:41 PM
  1. #1
    Registered User
    Join Date
    06-20-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    3

    Filter a Pivot table based on cell in another workbook

    Senerio

    I am creating report that copies cells from a "read only" pivot table and paste them to a different worksheet. I need the "year" field in the pivot table to only show the year that the user imputs into a cell.

    This is the code that I have now:

    Vyear = ActiveSheet.Range("H17")
    
    Windows("SCTS SGA Analysis File SCTS Rollup.xls").Activate
        Sheets("sheet1").Activate
    
    For Each PivotYear In ActiveSheet.PivotTables("PivotTable1").PivotField("Year").PivotItems()
           
            If PivotYear = Vyear Then
                With ActiveSheet.PivotTables("PivotTable1").PivotFields("Year")
                    .PivotItems(PivotYear).Visible = True
                End With
        
            Else
                
                With ActiveSheet.PivotTables("PivotTable1").PivotFields("Year")
                    .PivotItems(PivotYear).Visible = False
                End With
            End If
       Next
    When I recorded he macro and manually choose 2011 this is what appeared

        Windows("SCTS SGA Analysis File SCTS Rollup.xls").Activate
        ActiveSheet.PivotTables("PivotTable1").PivotFields("Year").CurrentPage = _
            "(All)"
        With ActiveSheet.PivotTables("PivotTable1").PivotFields("Year")
            .PivotItems("(blank)").Visible = False
            .PivotItems("2008").Visible = False
            .PivotItems("2009").Visible = False
            .PivotItems("2010").Visible = False
            .PivotItems("2011").Visible = True
            .PivotItems("2012").Visible = False
        End With
        ActiveSheet.PivotTables("PivotTable1").PivotFields("Year"). _
            EnableMultiplePageItems = True
    Unfortunately, I cannot post the workbooks because their content cannot be shared
    Last edited by nicknorth34; 07-15-2011 at 02:31 PM.

  2. #2
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Filter a Pivot table based on cell in another workbook

    HI nicknorth34, please re-read the forum rules located here and wrap your code in code tags as per Rule #3. Once you do that, someone will be able to help you.
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

+ 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