Solved

VBA for Excel to filter pivot table EXCLUDING "text"

Posted on 2016-08-10
4
37 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 31

Expert Comment

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

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
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.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now