none
How to get selected pivot items in a pivot table generated from Excel data model RRS feed

  • Question

  • Hi team,

    I got a pivot table generated via Excel data model like this:

    I want to use the following code the get all the selected items in the page fields:

    Sub tariff_table()
    Dim arr() As Variant
    Dim pt As PivotTable
    Set pt = Sheets("Pt Table").PivotTables("pt_slicer")
    Dim pi As PivotItem
    Dim pfld As PivotField

    For Each pfld In pt.PageFields
    For Each pi In pfld.PivotItems
    If pi.Selected Then
    s = s + 1
    ReDim Preserve arr(1 To s)
    arr(s) = pi.Name
    End If
    Next
    Next
    End Sub

    However, this code seems does not work for pivot table generates via Excel data model.

    Is there anyone can tell me how I can loop through selected pivot items in a pivot table generated via data model?

    Cheers,

    Tom Sun

    Monday, January 9, 2017 2:36 AM

All replies