Beny
Beny

Reputation: 3

Getting VBA to apply a filter to a pivot table

So as mentioned in the title I'm trying to apply a filter to a pivot table in my workbook as a part of a macro. I've tried dozens of different solutions from around the internet but to no avail.

This is what I've got so far, it successfully clears the old filters, so all I need is a line to assign filter "z" to the pivot field "IP5"

   Sub GetConsign()

    Dim y As Integer 
    Dim z As Integer 
    y = 4

    Worksheets("Master Data").Activate
    Cells(y, 7).Select
    z = Right(ActiveCell, 5)
    Worksheets("Cons Data").Activate

        Sheets("Cons Data").PivotTables("PivotTable3").PivotFields("IP5").ClearAllFilters

        'Need something to go here!

End Sub

I'd post an image of the table but apparently I need 10 reputation, nevermind.

Thanks, really appreciate any help I can get here, I'm bordering on insanity!

Upvotes: 0

Views: 9364

Answers (1)

Pavel_V
Pavel_V

Reputation: 1230

Try this

Sheets("Cons Data").PivotTables("PivotTable3").PivotFields("IP5").CurrentPage = "z"

or

Sheets("Cons Data").PivotTables("PivotTable3").PivotFields("IP5").PivotFilters.Add Type:=xlCaptionEquals, Value1:="z"

Upvotes: 1

Related Questions