Forum Discussion
Displaying Source of Pivot Table Above Pivot Table
- Apr 29, 2021
Activate the Visual Basic Editor (Alt+F11).
Select Insert > Module.
Copy the following code into the module:
Function PTSource(PTName As String) As String Dim pvt As PivotTable Set pvt = Application.Caller.Parent.PivotTables(PTName) PTSource = pvt.SourceData End FunctionSwitch back to Excel.
Use the following formula in a cell near the pivot table:
=PTSource("MyPivot")where MyPivot is the name of the pivot table (you can see this name when you click in the pivot table and activate the Analyze tab of the ribbon.
You will still have to edit the name in the formula if you rename the pivot table.
Don;t forget to save the workbook as a macro-enabled workbook (.xlsm) and to allow macros when you open it.
Activate the Visual Basic Editor (Alt+F11).
Select Insert > Module.
Copy the following code into the module:
Function PTSource(PTName As String) As String
Dim pvt As PivotTable
Set pvt = Application.Caller.Parent.PivotTables(PTName)
PTSource = pvt.SourceData
End Function
Switch back to Excel.
Use the following formula in a cell near the pivot table:
=PTSource("MyPivot")
where MyPivot is the name of the pivot table (you can see this name when you click in the pivot table and activate the Analyze tab of the ribbon.
You will still have to edit the name in the formula if you rename the pivot table.
Don;t forget to save the workbook as a macro-enabled workbook (.xlsm) and to allow macros when you open it.
- jchiappApr 29, 2021Copper Contributor
This awesome! I am going to have to try that. Knowing how Microsoft works, hopefully they are watching these posts, and add this as an additional function.
Thanks so much!