Excel Table Name

Copper Contributor

Hi

I want to make a selection of say 2 columns  59 rows, open the Table dialog box and in the 'name' box by default, should appear the header of the left hand most column, or a specified cell.   Not Table1 etc.

 

Can a formula be put into the   'Name' box?   to do this.  To save time over a number of tables.

 

Thanks

Charles Harris

3 Replies

Hi Charles

 

No you can't do that

 

It might also be worth considering voting for this user voice idea to allow people to change table name on creation of the table

 

https://excel.uservoice.com/forums/304921-excel-for-windows-desktop-application/suggestions/10580340...

 

 

Have done a vote and commented. Thanks Wyn for info. Charles

Charles,

 

This is can be done, but with some lines of code as follows:

Sub CreateTable()
    On Error Resume Next
    Dim tableName As String
    tableName = Selection.Cells(1, 1).Value
    If tableName = vbNullString Then Exit Sub
    ActiveSheet.ListObjects.Add(xlSrcRange, Selection, , xlYes).name = tableName
    On Error GoTo 0
End Sub

This code basically stores the value of the leftmost cell of the selected cells in a variable called tableName, then creates the table, and uses the value stored in this variable to name it.

 

Please follow this link to figure out how to insert and run this code.

 

Regards