Excel provides the GETPIVOTDATA() function.
GETPIVOTDATA(data_field, pivot_table, [field1, item1, field2, item2], ...)
Microsoft defines the pivot_table parameter this way: "A reference to any cell, range of cells, or named range of cells in a PivotTable. This information is used to determine which PivotTable contains the data that you want to retrieve."
So, in use on a sheet it looks like this: =GETPIVOTDATA("Row Cost",'Break Down'!$A$3,"Group",[@Group])
Pivot Tables have names, and I want to be able to use that name on the sheet. So far I have:
This works, but only by using it inside INDIRECT(), like this:
=GETPIVOTDATA("Hours Allocated",INDIRECT(GetPivotTopLeft("Break Down", "TechBreakDown")))
How can I get away from the need to use INDIRECT()?
=GETPIVOTDATA("Hours Allocated",GetPivotTopLeft("Break Down", "TechBreakDown"))
What VBA variable type does my GetPivotTopLeft() function need to return to make the native GETPIVOTDATA() function happy for the pivot_table parameter?
How do I build that type in my VBA function?
GETPIVOTDATA(data_field, pivot_table, [field1, item1, field2, item2], ...)
Microsoft defines the pivot_table parameter this way: "A reference to any cell, range of cells, or named range of cells in a PivotTable. This information is used to determine which PivotTable contains the data that you want to retrieve."
So, in use on a sheet it looks like this: =GETPIVOTDATA("Row Cost",'Break Down'!$A$3,"Group",[@Group])
Pivot Tables have names, and I want to be able to use that name on the sheet. So far I have:
Code:
Public Function GetPivotTopLeft(mySheet As String, TargetPT As String) As String
Dim PT As PivotTable
Dim TopLeftCell As String
Set PT = Worksheets(mySheet).PivotTables(TargetPT)
TopLeftCell = Split(PT.TableRange1.Address, ":")(0)
GetPivotTopLeft = "'" & Sheets(mySheet).Name & "'" & "!" & TopLeftCell
End Function
This works, but only by using it inside INDIRECT(), like this:
=GETPIVOTDATA("Hours Allocated",INDIRECT(GetPivotTopLeft("Break Down", "TechBreakDown")))
How can I get away from the need to use INDIRECT()?
=GETPIVOTDATA("Hours Allocated",GetPivotTopLeft("Break Down", "TechBreakDown"))
What VBA variable type does my GetPivotTopLeft() function need to return to make the native GETPIVOTDATA() function happy for the pivot_table parameter?
How do I build that type in my VBA function?