Get filters of pivot table fields

arianevergauwen

New Member
Joined
Jan 18, 2018
Messages
1
Hello,

I want to make a macro that loop thru the fields of a pivot table and get all filtervalues of each fields (in a array).
I already have some code but it gives errors with row- and columnfields an with hierachy filterfields .

Code:
Function SubScanPivot(Par_Pivot As String, Par_Pivotsheet As String) As Boolean
    Dim Wb As Workbook
    Dim ws As Worksheet
    Dim pvt As PivotTable
    Dim Filter() As Variant
    Dim pvt_field_name As String


    SubScanPivot = True
    
    Set Wb = Workbooks(gblWorkbookName)


    For Each pvt_field In Worksheets(Par_Pivotsheet).PivotTables(Par_Pivot).PivotFields
        blnOK = False
        
        '1 = RowField // 2 = ColomnField // 3 = FilterField // 4 = MeasuresField
        
        If pvt_field.Orientation = 1 Or _
            pvt_field.Orientation = 2 Or _
            pvt_field.Orientation = 3 Then
            pvt_field_name = pvt_field.Name
            
            Filter = Workbooks(gblWorkbookName).Sheets(Par_Pivotsheet).PivotTables(Par_Pivot).PivotFields(pvt_field_name).VisibleItemsList
            
            If Filter(1) = "" Then
                If pvt_field.Orientation <> 1 And pvt_field.Orientation <> 2 Then
                    Filter(1) = Workbooks(gblWorkbookName).Sheets(Par_Pivotsheet).PivotTables(Par_Pivot).PivotFields(pvt_field_name).CurrentPageName
                End If
            End If
            
            If Filter(1) <> "" Then
                If UBound(Filter) > 1 Then
                    For I = 1 To UBound(Filter)
                        DoSomeThing1
                    Next
                ElseIf UBound(Filter) = 1 Then
                    DoSomeThing2
                End If
            End If
        End If
    Next pvt_field
    
    Exit Function
    
err_SubScanPivot:
    MsgBox "Error in SubScanPivot: (" & Err.Number & ") - " & Err.Description
    Resume Next
End Function
Can someone help me?

Grts
Ariane
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Forum statistics

Threads
1,214,780
Messages
6,121,522
Members
449,037
Latest member
tmmotairi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top