Forum Discussion

jchiapp's avatar
jchiapp
Copper Contributor
Apr 29, 2021
Solved

Displaying Source of Pivot Table Above Pivot Table

Colleagues I was wondering/hoping that there is a function that allows me to display the source of a pivot table above the pivot table?   I ask because I create a number of pivot tables and often ...
  • HansVogelaar's avatar
    Apr 29, 2021

    jchiapp 

    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.

Resources