• 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.

VBA Clearing only selected fields from pivot

Christof

Member
Hi,

Is it possible to have it that my macro doesn't clear all filters on my pivot table, but instead just clears 2 of them?

Basically on the below code, I only want Field2 to be reset, rather than Field1, Field11, Field15 and Field2.

Thanks



Code:
        Set pt1 = PivotTables("PivotTable1")
        Set Field1 = pt1.PivotFields("Brand")
        Set Field11 = pt1.PivotFields("Country")
        Set Field15 = pt1.PivotFields("New Product Group")
        pt1.ManualUpdate = True

        sumField = Range("C3").Value
        With pt1.PivotFields(Yeartype)
            .Orientation = xlRowField
            .Position = 1
        End With
        If Yeartype = "Financial Year" Then
            pt1.PivotFields("Calendar Year").Orientation = xlHidden
            Set Field2 = pt1.PivotFields("Financial Year2")
        Else
            pt1.PivotFields("Financial Year").Orientation = xlHidden
            Set Field2 = pt1.PivotFields("Calendar Year2")
        End If


        pt1.DataFields(1).Orientation = xlHidden
        pt1.PivotFields(sumField).Orientation = xlDataField
       
        pt1.AllowMultipleFilters = True

       
        pt1.ClearAllFilters
       
        Field1.CurrentPage = NewCat1
        Field11.CurrentPage = NewCat5
        Field15.CurrentPage = NewCat6
       
        For Each pi In Field2.PivotItems
            If Not ((pi.Name = NewCat2) Or (pi.Name = NewCat3)) Then
                pi.Visible = False
            End If
        Next
        pt1.ManualUpdate = False
        pt1.RefreshTable
 
Back
Top