Results 1 to 2 of 2

Filter a pivot table by list in a range

Threaded View

  1. #1
    Registered User
    Join Date
    09-17-2012
    Location
    Alabama
    MS-Off Ver
    Excel 2007
    Posts
    5

    Filter a pivot table by list in a range

    I need some help with some poetry. I want a macro that will filter a pivot table based on items listed in a range in another worksheet. Here is what I have so far:

    Sub Filter_PT_By_List
    
    'Filter a pivot table to exclude all items in the "DEPT" field except for those listed in "MyRange"
    
         For Each PivotItem In Worksheets("Sheet1").PivotTables("PivotTable1").PivotFields("DEPT").PivotItems
         '
    	If WorksheetFunction.IsNA(WorksheetFunction.VLookup(PivotItem.Name, Worksheets("Sheet2").Range("MyRange"), 1, False)) Then
    	   PivotItem.Visible = False
    	   Else
    	   PivotItem.Visible = True
    	End If
         Next PivotItem
    End Sub
    The line that begins with "If WorksheetFunction..." seems awkward. That line is supposed to emulate a VLookup function which, if it evaluates to "#N/A", causes the PivotItem to be hidden. I either need to make this line work or find a completely different approach.

    Thanks


    Moderator Edit:

    Welcome to the forum, MikeWard100.

    Please notice that code tags have been added to your post. The forum rules require them so please keep that in mind and add them yourself whenever showing code in any of your future posts. To see instructions for applying them, click on the Forum Rules button at the top of the page and read Rule #3.
    Thanks.
    Last edited by Cutter; 09-20-2012 at 11:12 AM. Reason: Added code tags

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