David S.
David S.

Reputation: 119

Input cell address, get table name

I am looking for some excel VBA code that when I input a cell address it'll give me the name of the table that that cell is apart of of and store the name of the table in a variable. I would also like to store the cell address in a variable called "GetCellsTable".

Is there anyway I can go about doing this?

Example:

Dim StoreTableName as String?
Dim GetCellsTable as ?
StoreTableName = Range(GetCellsTable).ListObject.Name

Upvotes: 2

Views: 247

Answers (1)

Excel Developers
Excel Developers

Reputation: 2825

MyVariable = SomeCell.ListObject.Name

Edit:

If you want to store the cell address (say cell "A3") in a variable and then use it to get the table name:

Dim GetCellsTable As String
GetCellsTable = "A3"
MyTableName = Range(GetCellsTable).ListObject.Name

Or, if you want to store the cell itself as a range object in a variable:

Dim GetCellsTable as Range
Set GetCellsTable = Range("A3")
MyTableName = GetCellsTable.ListObject.Name

Upvotes: 3

Related Questions