VBA function to return selected pivot item from page field

Harry Flashman

Active Member
Joined
May 1, 2011
Messages
356
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 fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

mart37

Well-known Member
Joined
Aug 4, 2017
Messages
1,090
Office Version
  1. 2016
Platform
  1. Windows
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
 
Solution

Harry Flashman

Active Member
Joined
May 1, 2011
Messages
356
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,352
Messages
5,635,780
Members
416,880
Latest member
kyleswanson

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
Top