Solved

VBA for Excel to filter pivot table EXCLUDING "text"

Posted on 2016-08-10
4
57 Views
Last Modified: 2016-08-10
I have a basic question on how to EXCLUDE an item from a Pivot Table Filter.

A snippet of my code is below
    Set myPivotTableField = myPivotTable.PivotFields("Category Filter")
    myPivotTableField.Orientation = xlPageField
    myPivotTableField.Position = 1
    Set myPivotTableField = myPivotTable.PivotFields("Category Filter")
    myPivotTableField.CurrentPage = "Cars"

Open in new window


Now this will Filter "Cars" from the Category Filter.

However, I would like to EXCLUDE "Cars" from the filter
Something Like : myPivotTableField.CurrentPage <> "Cars"

But this syntax does not work.   Is there an easy way to NOT include "Cars" ?

Thanks
0
Comment
Question by:Mchallinor
  • 2
4 Comments
 

Author Comment

by:Mchallinor
ID: 41750215
How do I convert the following to a VBA syntax?
   
 
With ActiveSheet.PivotTables("PivotTable").PivotFields("Category Filter")
        .PivotItems("Cars").Visible = False

Open in new window

0
 
LVL 32

Expert Comment

by:Rob Henson
ID: 41750216
That looks like it already is VBA syntax.
0
 
LVL 49

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 41750228
HI,

Maybe

For Each pvtItm In myPivotTableField.PivotItems
    If pvtItm.Name <> "Cars" Then
        pvtItm.Visible = True
    Else
        pvtItm.Visible = False
    End if
Next

Open in new window

Regards
0
 

Author Closing Comment

by:Mchallinor
ID: 41750234
Set myPivotTableField = myPivotTable.PivotFields("Category Filter")
    myPivotTableField.EnableMultiplePageItems = True          
    myPivotTableField.PivotItems("Cars").Visible = False


After posting I worked out my own answer!!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Modern/Metro styled message box and input box that directly can replace MsgBox() and InputBox()in Microsoft Access 2013 and later. Also included is a preconfigured error box to be used in error handling.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question