Excel VBA Current Table Name

JeannetteE

Board Regular
Joined
May 19, 2016
Messages
53
Hi,

I have a Worksheet with multiple Tables, how can I find the Table Name of the Table I'm currently in? Everything seems to point to ListObject(1) but I don't know which ListObject Number it is.

Any help appreciated :)
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Hi there, I'm not sure if this is what you are looking for, but if you just want the name of the table, you can use:

Code:
ActiveCell.ListObject.Name
 
Upvote 0
Hi there, I'm not sure if this is what you are looking for, but if you just want the name of the table, you can use:

Code:
ActiveCell.ListObject.Name

Thank you, so easy! I've tried the same principle for the Header Name but it doesn't work, ActiveCell.ListColumn.Name nd other variants. Apologies but Tables are new to me.
 
Upvote 0
Thank you, so easy! I've tried the same principle for the Header Name but it doesn't work, ActiveCell.ListColumn.Name nd other variants. Apologies but Tables are new to me.

No problem. If you wish to get the header name for the active cell in the table, you can use something like this:

Code:
Dim ws As Worksheet
Dim tName As String
Dim hName As String
Dim i As Integer

Set ws = ActiveSheet

tName = ActiveCell.ListObject.Name

i = ActiveCell.Column - ActiveCell.ListObject.DataBodyRange.Column + 1
hName = ws.ListObjects(tName).ListColumns(i).Name

MsgBox (hName)
 
Last edited:
Upvote 0
No problem. If you wish to get the header name for the active cell in the table, you can use something like this:

Code:
Dim ws As Worksheet
Dim tName As String
Dim hName As String
Dim i As Integer

Set ws = ActiveSheet

tName = ActiveCell.ListObject.Name

i = ActiveCell.Column - ActiveCell.ListObject.DataBodyRange.Column + 1
hName = ws.ListObjects(tName).ListColumns(i).Name

MsgBox (hName)

Thank you so much!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top