Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Store List of ChildItems from OLAP pivot table in an Array

Status
Not open for further replies.

hrm1220

Technical User
Aug 31, 2005
134
US
I have several worksheets with a pivot table on each worksheet from OLAP source in Excel 2007.

The goal is to get the group1 (Parent), group2 (Parent child),and group3 (child).
example:
Group1 (the variant [purple]VarField (1,x)[/purple]) Mammal
Group2 (the variant [purple]VarField (2,x)[/purple]) Dog
Group3 (the variant [purple]VarField (3,x)[/purple]) German Shepard


I've tried several times to try to get a list stored in an array, but doesn't seem to work.

Code:
Dim pvt As PivotTable, PI As PivotItemList
Dim ws As Worksheet, [purple]varField[/purple] as Variant
Dim pitem As PivotItem, ch


ReDim varField(3, x)
For Each ws In ActiveWorkbook.Worksheets
For Each pvt In ws.PivotTables
Application.Calculation = xlCalculationManual
x=0
 With pvt.PivotFields("[Animal].[Parent Child Animal Group].[Type]")

    For Each pitem In .PivotItems
        For Each ch In pvt.PivotFields("[Animal].[Parent Child Animal Group].[Type]").PivotItems(pitem).ChildItems
        
    

    ReDim varField(3, x)
   varField(1, x - 1) = .PivotItems(pitem).Value
   varField(2, x - 1) = .PivotItems(ch).Value
   varField(3, x - 1) = .PivotItems(x).Value
  x=x+1
        
        Next ch
    Next pitem
  End With
Next pvt
Next ws

Any help would be greatly appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top