How to display table or pivot table name in a cell in Excel?
This article is talking about displaying a specified table or pivot table name in a cell in Excel.
- Reuse Anything: Add the most used or complex formulas, charts and anything else to your favorites, and quickly reuse them in the future.
- More than 20 text features: Extract Number from Text String; Extract or Remove Part of Texts; Convert Numbers and Currencies to English Words.
- Merge Tools: Multiple Workbooks and Sheets into One; Merge Multiple Cells/Rows/Columns Without Losing Data; Merge Duplicate Rows and Sum.
- Split Tools: Split Data into Multiple Sheets Based on Value; One Workbook to Multiple Excel, PDF or CSV Files; One Column to Multiple Columns.
- Paste Skipping Hidden/Filtered Rows; Count And Sum by Background Color; Send Personalized Emails to Multiple Recipients in Bulk.
- Super Filter: Create advanced filter schemes and apply to any sheets; Sort by week, day, frequency and more; Filter by bold, formulas, comment...
- More than 300 powerful features; Works with Office 2007-2019 and 365; Supports all languages; Easy deploying in your enterprise or organization.
The following VBA code can help you display a specified table or pivot table name in a cell. Please do as follows.
1. Press the Alt + F11 keys to open the Microsoft Visual Basic for Applications window.
2. In the Microsoft Visual Basic for Applications window, click Insert > Module. Then copy below VBA code into the Module window.
VBA code: Display table or pivot table name in a cell
Function getObjName(rng As Range) As String ‘Updated by Extendoffice 20180420 Dim xTable As ListObject Dim xPivotTable As PivotTable Dim xTableName As String Dim xPtName As String On Error Resume Next xTableName = "" xPtName = "" Set xTable = rng.Cells(1).ListObject xTableName = "Table[" & xTable.Name & "]" If xTable Is Nothing Then Set xPivotTable = rng.Cells(1).PivotTable xPtName = "Pivot [" & xPivotTable.Name & "]" End If getObjName = xTableName & xPtName End Function
3. Press the Alt + Q keys to exit the Microsoft Visual Basic for Applications window.
4. Select a blank cell, enter formula =getObjName(A2) into the Formula Bar and then press the Enter key. See screenshot:
1. In the formula, A2 is the cell of the table you want to display the name. You can reference any cell of the table range as you need.
2. For displaying pivot table name, please change A2 in the formula to any cell within the pivot table.
- How to list all table names in Excel?
- How to keep table expandable by inserting table row in a protected worksheet in Excel?
- How to reorder position of columns in table in Excel?
- How to hide zero value rows in pivot table?