Excel使用VBA迭代嵌套数据透视表行场

我有一个数据透视表,我需要遍历嵌套的RowFields:

示例数据透视表

我怎样才能parsing嵌套的RowFields?

我的代码到目前为止是:

Sub PtRead() Dim i As Integer, j As Integer Dim Sh As Worksheet Dim pt As PivotTable Dim rngRow As Range Set Sh = Sheets("Store") Set pt = Sh.PivotTables(1) i = 3 For j = 1 To pt.RowFields(i).PivotItems.Count Debug.Print pt.RowFields(i).PivotItems(j) Next End Sub 

我需要检索,例如,与品牌“AAA”有关的所有嵌套的物品代码和相关的Nsum值类似(这是行不通的..):

 ... pt.RowFields(1).PivotItems(1).RowFields(2).PivotItems(j) ... 

我想你想循环通过枢轴项目。 查看下面的代码,获取有关如何继续的一些指导。

 Sub TryMe() For Each Pi In ActiveSheet.PivotTables("PivotTable1").PivotFields("DeptHead").PivotItems If Pi.Visible Then Count = Count + 1 Range("B" & Count).Value = Pi.Name Row = Row + 1 End If Next Pi End Sub 

macroslogging器是非常有用的,如果你遇到困难的事情。