VBA function to return selected pivot item from page field

Harry Flashman

Active Member
Joined
May 1, 2011
Messages
361
Is there a property that returns the name of the selected pivot item in a pivot field (especially a page field)?
Or do I need to loop through every pivot item and check its visible status?

In my case the page field is a selected month such as "January 2021". Sometime more than one month will be selected in which case the pivot table will display "(Multiple Items") or "(All)". Whatever the page field shows as being select I would like to return that value.

Any assistance would be greatly appreciated.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
I am afraid you need a loop like:
VBA Code:
    Dim i As PivotItem
    For Each i In ActiveSheet.PivotTables("PivotTable1").PivotFields("Month").PivotItems
        Debug.Print i.Name & ": " & i.Visible
    Next
 
Upvote 0
Solution
Sorry for the late reply mart37. I only just realized that someone had replied.

Yes I figured that out eventually. I used to know this, but its been so long long since I have written any VBA. I end-up writing a function that returns that value that I need. Thanks.
 
Upvote 0

Forum statistics

Threads
1,214,806
Messages
6,121,667
Members
449,045
Latest member
Marcus05

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