+ Reply to Thread
Results 1 to 2 of 2

Check if a filter exists on a pivot table

Hybrid View

spinkung Check if a filter exists on a... 01-07-2010, 10:44 AM
DonkeyOte Re: Check if a filter exists... 01-07-2010, 12:03 PM
  1. #1
    Forum Contributor spinkung's Avatar
    Join Date
    10-27-2006
    Posts
    199

    Check if a filter exists on a pivot table

    Hi all,

    i am running some code which loops through the pivot table on a sheet and applies a filter. Not all of the pivot tables have the filter field though. Is there something i can do to test whether the filed is on the pivot first??

    i have this...
    For Each pivotTbl In pivotSht.PivotTables
        pivotNm = pivotTbl.Name
            pivotSht.PivotTables(pivotNm).PivotFields("tier").CurrentPage = "(All)"
            With pivotSht.PivotTables(pivotNm).PivotFields("tier")
                .PivotItems("1").Visible = True
                .PivotItems("2").Visible = True
                .PivotItems("NP").Visible = True
            End With
    Next
    ..but if the filed 'tier' doesn;t exist i ge an error.

    Thanks,
    Spin.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Check if a filter exists on a pivot table

    Perhaps... (untested)

    Dim pivotSht As Worksheet
    Dim pivotTbl As PivotTable
    Dim PTFilter As PivotField
    Set pivotSht = Sheets("sheetname")
    For Each pivotTbl In pivotSht.PivotTables
        With pivotTbl
            .ManualUpdate = True
            On Error Resume Next
            Set PTFilter = pivotTbl.PivotFields("tier")
            On Error GoTo 0
            If Not PTFilter Is Nothing Then
                With PTFilter
                    .CurrentPage = "(All)"
                    .PivotItems("1").Visible = True
                    .PivotItems("2").Visible = True
                    .PivotItems("NP").Visible = True
                End With
            End If
            Set PTFilter = Nothing
            .ManualUpdate = False
        End With
    Next pivotTbl
    Set pivotSht = Nothing

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1