How to find the items in a pivot field collection

Glory

Well-known Member
Joined
Mar 16, 2011
Messages
640
I've tried a ridiculous assortment of statements and nothing is working.

As far as I can tell from VBA's help it should just be:

Code:
For Each Pvt in ActiveSheet.PivotTables("Name").PivotFields("Name").Item
MsgBox Pvt
Next

In fact, I shouldn't even need to put the "Item" on there, because the default method for all collections is "Item".

But it's not working.
 
Last edited:

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
May be...


Rich (BB code):
For Each Pvt in ActiveSheet.PivotTables("Name").PivotFields("Name").Items
MsgBox Pvt.Name
Next
 
Upvote 0
I've already tried that. I don't need the name. I need the ability to iterate through the list of items in the single PivotFields object I'm trying to work with.

I need to be able to check all the entries in a pivot drop-down, including those contained only in the pivot table's cache.

Edit: I do appreciate the post, though.
 
Last edited:
Upvote 0
This loops through all the items in the PivotField "Name"

Code:
For Each Pvt In ActiveSheet.PivotTables("Name").PivotFields("Name")[COLOR="Red"].PivotItems[/COLOR]
MsgBox Pvt
Next

If you DIM a variable as a PivotField, that will bring up the intellisense pop-up help for pivotfields e.g.

Code:
Dim pvt As PivotItem
Dim pf As PivotField

Set pf = ActiveSheet.PivotTables("Name").PivotFields("Name")

For Each pvt In pf.PivotItems
MsgBox pvt
Next

type pf. brings the intellisense pop-up help.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,543
Members
452,924
Latest member
JackiG

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