Written by Allen Wyatt (last updated November 19, 2022)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021
David wonders if there is a way to display a PivotTable's name within the PivotTable itself.
The short answer is that there is no way to do this automatically. The longer answer is that you can "cheat" and force a name into the PivotTable. For instance, you could select the row label cell in the PivotTable and edit it (F2), replacing whatever is there with whatever name you want to type. This is far from automatic, and when you refresh the PivotTable, you'll need to remember to edit the cell again.
Another way to force a name into the PivotTable is to use a macro. There are probably a few approaches you could take in your macro. One approach is to create a data table on which your PivotTable will be based. Give the data table a heading, in the first column. (Any old text for the heading will do, as the macro will overwrite it.)
After you create your PivotTable, run the following macro. It determines the name of the PivotTable, stuffs it into the heading of the data table, refreshes the PivotTable (so the name appears there), and then updates the name of the PivotTable report filter so it is the same as the PivotTable name.
Sub GetPVName() Dim pvt As PivotTable Dim PVName As String ' Get the PivotTable name from the ActiveSheet ' If there are multiple PivotTables, this approach ' ensures the macro will work with the last PivotTable ' in the PivotTables collection For Each pvt In ActiveSheet.PivotTables PVName = pvt.Name Next pvt ' Put PivotTable name as a heading for the first ' column of the data table Range("Table1").Cells(0, 1) = PVName ' Refresh the PivotTable ActiveSheet.PivotTables(PVName).PivotCache.Refresh ' Set the PivotTable name in the report filter With ActiveSheet.PivotTables(PVName).PivotFields(PVName) .Orientation = xlPageField .Position = 1 End With End Sub
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (3233) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021.
Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!
When you want to include specific records from a source table into a PivotTable, you need to employ some sort of ...
Discover MoreIf you modify the data on which a PivotTable is based, you'll need to refresh the table so it reflects the modified data. ...
Discover MoreAre you attached to the classic PivotTable layout? Looking for a way to make that layout the default for new PivotTables? ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments