Matching Pivot Table DISPLAY Order to PivotItem Indexing Order

DeadGoat

New Member
Joined
May 15, 2014
Messages
4
Hello All,
Objective: Seeking solution to extract Pivot table index Item value that matches display order.

Description:Simple For Each loop that indexes through the Pivot Table return pivotItems based on ascending order.

What I need is a way for vba to return pvtItem content based on the pivotTable DISPLAY order.

Any help is greatly appreciated.
PivotTable DISPLAY order example:

[TABLE="width: 167"]
<tbody>[TR]
[TD]Category1[/TD]
[TD]Category2[/TD]
[/TR]
[TR]
[TD]Boat[/TD]
[TD]T24TTJ[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]UFEGE[/TD]
[/TR]
[TR]
[TD]Car[/TD]
[TD]J45631

[/TD]
[/TR]
</tbody>[/TABLE]


...
For Each pvtField In pvtTable.PivotFields
For Each pvtItem In pvtField.PivotItems
debug.print pvtItem
Next pvtItem
Next pvtField
...

Result:
J45631
T24TTJ
UFEGE

If I look query in the vba debugger I see:
Pvtfield.pivotItems(1).Name
J45631
Pvtfield.pivotItems(2).Name
T24TTJ
Pvtfield.pivotItems(3).Name
UFEGE

This is all wonderful, but I don't want PivotTable to sort when I index through the items. I want VBA index to return based on Display as:

Pvtfield.pivotItems(1).Name
T24TTJ
Pvtfield.pivotItems(2).Name
UFEGE
Pvtfield.pivotItems(3).Name
J45631


Any suggestions on how this can be done.

Thank you!
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Maybe try:

Code:
Sub Test()
    Dim r As Long
    With ActiveSheet.PivotTables(1).RowRange
        For r = 2 To .Rows.Count
            Debug.Print Cells(r, 2).Value
        Next r
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,885
Members
452,364
Latest member
springate

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