How to display table or pivot table name in a cell in Excel?
This article explains how to display the name of a specific table or pivot table in a cell in Excel.
Display table or pivot table name in a cell with VBA code
Display table or pivot table name in a cell with VBA code
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 the VBA code below 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:
Notes:
Related articles:
- 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?
Best Office Productivity Tools
Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time. Click Here to Get The Feature You Need The Most...
Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
- Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
- Open and create multiple documents in new tabs of the same window, rather than in new windows.
- Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
All Kutools add-ins. One installer
Kutools for Office suite bundles add-ins for Excel, Word, Outlook & PowerPoint plus Office Tab Pro, which is ideal for teams working across Office apps.





- All-in-one suite — Excel, Word, Outlook & PowerPoint add-ins + Office Tab Pro
- One installer, one license — set up in minutes (MSI-ready)
- Works better together — streamlined productivity across Office apps
- 30-day full-featured trial — no registration, no credit card
- Best value — save vs buying individual add-in