Pivot Table Relative References

J

Jimmy

Looking for help with VBA code.

I would like to store in a variable the amount of child categories that
are part of a given row or column.

Are pivot table size details referenced in any functions?

My user requires a formula inserted to the bottom of the pivot which
will summarize the above data. This requires knowing the cell
locations to put into these formulas.

Thank you,

JR
 
M

Mark Driscol

If the ActiveCell is in the pivot table, the code below can get the
addresses of the pivot table row and column the cell is in.

Option Explicit

Sub GetPivotTableInfo()

Dim rngDataRange As Range
Dim rngRow As Range
Dim rngColumn As Range

Set rngDataRange = Application.ActiveCell.PivotField.DataRange
Set rngRow = Intersect(Rows(ActiveCell.Row), rngDataRange)
Set rngColumn = Intersect(Columns(ActiveCell.Column), rngDataRange)

MsgBox "Row address: " & rngRow.Address
MsgBox "Column address: " & rngColumn.Address

End Sub


Mark
 
J

Jimmy

Thanks.
It works!


Mark said:
If the ActiveCell is in the pivot table, the code below can get the
addresses of the pivot table row and column the cell is in.

Option Explicit

Sub GetPivotTableInfo()

Dim rngDataRange As Range
Dim rngRow As Range
Dim rngColumn As Range

Set rngDataRange = Application.ActiveCell.PivotField.DataRange
Set rngRow = Intersect(Rows(ActiveCell.Row), rngDataRange)
Set rngColumn = Intersect(Columns(ActiveCell.Column), rngDataRange)

MsgBox "Row address: " & rngRow.Address
MsgBox "Column address: " & rngColumn.Address

End Sub


Mark
 

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

Top