VBA Code to obtain Table Name

Anonymous
2022-05-10T13:24:14+00:00

I have the following table. What is the code to pull that table name (TESTAUDIT) to use in a macro?

I have the following code to uncheck a couple of items but need to replace the "TABLE1" with the actual table name:

'Uncheck the Headers and Banded Rows in table

ActiveSheet.ListObjects("Table1").ShowHeaders = False
ActiveSheet.ListObjects("Table1").ShowTableStyleRowStripes = False

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes
Answer accepted by question author
  1. Anonymous
    2022-05-10T13:40:18+00:00

    With active cell in the table, try
    ActiveCell.ListObject.Name

    if you want to call from anywhere else

    Try this function. It will give you the table name

    Function CellInTable(thisCell As Range) As String

    Dim tableName As String 
    
    tableName = "" 
    
    On Error Resume Next 
    
    tableName = thisCell.ListObject.Name 
    
    CellInTable = tableName 
    

    End Function

    to call the function, pass it the address of any cell in the table or click on any cell in the table and pass ACTIVECELL

    Sub Test()

    Debug.Print CellInTable(ThisWorkbook.Worksheets("Sheet4").Range("A1"))

    End Sub

    Sub Test2()

    Debug.Print CellInTable(ActiveCell)

    End Sub

    4 people found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Andreas Killer 144K Reputation points Volunteer Moderator
    2022-05-10T13:37:05+00:00

    ActiveSheet.ListObjects(1).ShowHeaders = False

    ActiveSheet.ListObjects(1).ShowTableStyleRowStripes = False

    0 comments No comments