ChildItems and ParentItem of PivotItem object dont seem to work

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi there,

I need to retrive data from a pivot table that is not from an OLAP source. I
need to get the data for a item and then also display that data for the
parent of that item. Basically they want to see sales for a particular
product and then the sales of that product group. There are hundreds of
products so I need to be able to lookup its parent from the pivot table. Once
I have the parent I can retrieve data using getPivotData.

However I just get the message ""Unable to get the ParentItem property of
the PivotItem"

It says something similar if I try to get the ChildItems collection.

Any help is appreciated.
 
ParentItem and ChildItem are for grouped items. The following code
should work for adjacent column fields.

'==============================
Sub GetOuterFieldItem()
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Dim rngPG As Range

Set pt = ActiveSheet.PivotTables(1)
Set pf = pt.PivotFields("Product")
Set pi = pf.PivotItems("ProductA")
Set rngPG = Range(pi.LabelRange.Address).Offset(0, -1)

Debug.Print rngPG.PivotItem.Name

End Sub
'========================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top