Forum Discussion
Charles Harris
Apr 22, 2018Copper Contributor
Excel Table Name
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...
Haytham Amairah
Apr 23, 2018Silver Contributor
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 https://www.ablebits.com/office-addins-blog/2013/12/06/add-run-vba-macro-excel/ to figure out how to insert and run this code.
Regards