+ Reply to Thread
Results 1 to 2 of 2

VBA code to update pivot to "blank" if item in not found in pivot filter

Hybrid View

  1. #1
    Registered User
    Join Date
    04-09-2014
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    1

    VBA code to update pivot to "blank" if item in not found in pivot filter

    Hi all, I Have this code below looking at a specific cell, based on the name in that cell X7 (also stated as New Cat), The code selects that same name in the pivot table filter (Resource Pool Name).
    By selecting this name the pivot itself displays data that is tied to this name.

    Problem: If the name in X7 (New Cat) is not in the pivot, the code just shows all data for all Resource Pool Names (no Filter at all)

    How do I update my code to do what it's doing but if the name in x7 does not exist in the pivot to just select "blank"
    in the Resource Pool Name filter



     'Set the Variables to be used
                    Dim pt As PivotTable
                    Dim Field As PivotField
                    Dim NewCat As String
                     
                    'Here you amend to suit your data
                    Set pt = Worksheets("ENG").PivotTables("ENGDmd")
                    Set Field = pt.PivotFields("Resource Pool Name")
                    NewCat = Worksheets("ENG").Range("x7").Value
                    
                   
                    
                            If NewCat = "" Then
                        Exit Sub
                    End If
                    
                    'This updates and refreshes the PIVOT table
                    With pt
                        Field.ClearAllFilters
                        Field.CurrentPage = NewCat
                    End With

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: VBA code to update pivot to "blank" if item in not found in pivot filter

    I didn't test this, but give it a try...

    'This updates and refreshes the PIVOT table
    With pt
        Field.ClearAllFilters
        Field.CurrentPage = NewCat
        If Field.CurrentPage <> NewCat Then Field.CurrentPage = "(blank)"
    End With
    Last edited by AlphaFrog; 05-13-2014 at 11:46 PM.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 1
    Last Post: 01-18-2014, 08:45 AM
  2. VBA to filter "(Blank)" cells in pivot table , but in foreign languages too.
    By MarMo in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-07-2013, 11:27 AM
  3. Filter report in pivot table with "greater than" and "less than"
    By gygabyte017 in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 12-29-2012, 08:08 AM
  4. Replies: 1
    Last Post: 04-07-2012, 04:36 PM
  5. [SOLVED] How do I filter "Blank" cells in Pivot Table
    By Felipe Brochier in forum Excel General
    Replies: 0
    Last Post: 07-31-2006, 09:18 AM

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