Solved

VBA for Excel to filter pivot table EXCLUDING "text"

Posted on 2016-08-10
4
121 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 33

Expert Comment

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

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

626 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