extract data value from Pivot filter (Multiple Items)

yessuz

New Member
Joined
Apr 18, 2013
Messages
18
Hi Guys,

i wonder if there is any way to extract the value of the filter on the pivot table when you select more than 1 criteria?

For example:
If my filter criteria has "apples", "Pears", "oranges" and I select "Apples" and "pears" in the filter criteria, the value of the filter is shown as (Multiple Items)
If I select "Oranges" - the value of filter is shown as Oranges.

then I can use the formula to get the cell value of the cell.

But when the multiple items is selected, the value is just (Multiple Items).

Is there any way to extract the value of filter criteria in order to get Apples and Oranges as the result?

thanks!!!
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Try this UDF:

Code:
Public Function Get_PT_Field_Items(PivotTableName As String, PivotField As String) As String

    Dim PT As PivotTable
    Dim PTfield As PivotField
    Dim PTitem As PivotItem
    
    Set PT = ActiveSheet.PivotTables(PivotTableName)
    Set PTfield = PT.PivotFields(PivotField)
    
    Get_PT_Field_Items = ""
    For Each PTitem In PTfield.PivotItems
        Debug.Print PTitem.Name
        If PTitem.Visible Then Get_PT_Field_Items = Get_PT_Field_Items & PTitem.Name & ", "
    Next
    
    If Get_PT_Field_Items <> "" Then
        Get_PT_Field_Items = Left(Get_PT_Field_Items, Len(Get_PT_Field_Items) - 2)
    End If
    
End Function
Use it like this in a cell formula:

=Get_PT_Field_Items("PivotTable1","Fruit")

where "PivotTable1" is the name of the pivot table and "Fruit" is the name of the field.

However, the above cell formula is not recalculated when you change the filter field items. Instead you have to call it from the Worksheet_PivotTableUpdate event:

Code:
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
    Range("H1").Value = Get_PT_Field_Items(Target.Name, "Fruit")
End Sub
where H1 is the cell you want to contain the list of selected items.
 
Upvote 0

Forum statistics

Threads
1,214,661
Messages
6,120,790
Members
448,994
Latest member
rohitsomani

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