• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Filter Pivot Table based in more than one cell reference

kdibai

New Member
Hello,


I have this code bellow that filter a pivot table based in one cell input. But I want to be able to select more than one filter in the pivot table.

Already tried to modify the range for more than one cell but didn't work... There's nothing on the web with an answer for that!


Dim PT As PivotTable

Set PT = Sheets("MySheet").PivotTables("MyPivot")

PT.PivotFields("MyField").CurrentPage = Sheets("MySheet").Range("D1").Value

Set PT = Nothing


Another thing: How do I make it run automatically? I tried to build a regular Private Sub with the code working but wasn't able with my macro knowledge.
 
No anwsers here, but I manage to solve that after huge ammount of searching. I'll anwser my question in case someone else need it.


source: http://www.mrexcel.com/forum/showthread.php?475636-Filter-values-in-pivot-table-by-reference-to-a-range


I modified the macro to be able to filter not only in filter but in line labels filter too.


Sub TopA()

'

Dim PT As PivotTable

Dim PI As PivotItem

Set PT = Sheets("YourSheetName").PivotTables("PivotTableName")

For Each PI In PT.PivotFields("FilterName").PivotItems

PI.Visible = WorksheetFunction.CountIf(Sheets("YouSheetNamewiththeRange").Range(A1:A6), PI.Name) > 0

Next PI

Set PT = Nothing

End Sub
 
Hi, kdibai!

Glad you solved it. Thanks for your feedback and for sharing your solution with everybody. Welcome back whenever needed or wanted.

Regards!
 
Back
Top