Share via

Loop through only Visible PivotItems

Anonymous
2012-10-10T06:37:47+00:00

Hi,

I have a pivot table and I have one field in my row labels, the field is called bill_to, in my column labels I have a field called product, and in my values area of the pivot table I have a field called amount.  I'm placing a filter on a product value and the pivot table is then showing me the bill_to clients whom revenue was generated from for those products.  How do I loop through the bill_to column and grab only the bill_to clients that are visible on the pivot table, at the moment I'm using the PivotItem Object but that appears to be looping through all bill_to clients and not just the ones that I can see on the pivot table based on the filters applied.

Thanks.

Simon

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. HansV 462.6K Reputation points
    2012-10-10T09:21:51+00:00

    The PivotITem object has a Visible property, so within your loop you can check whether the items is visible:

        Dim pvi As PivotItem

        For Each pvi In ...

            If pvi.Visible Then

                ' Your stuff here

                ...

            End If

        Next pvi

    Was this answer helpful?

    0 comments No comments