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:

Category1Category2
BoatT24TTJ
UFEGE
CarJ45631


<tbody>
</tbody>


...
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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
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,221,418
Messages
6,159,791
Members
451,589
Latest member
Harold14

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