Solved

VBA for Excel to filter pivot table EXCLUDING "text"

Posted on 2016-08-10
4
68 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 33

Expert Comment

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

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

839 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