Create an Excel Table from the Selection
Sub CreateTable()
Dim Sr As Range
Dim Ws As Worksheet
Dim Tb As ListObject
Set Sr = Selection.CurrentRegion
Set Ws = ActiveSheet
Set Tb = Ws.ListObjects.Add(SourceType:=xlSrcRange, Source:=Sr, XlListObjecthasheaders:=xlYes)
End Sub
Convert a data range into a Table with a specific Name
Sub CreateTableWithName()
Dim Sr As Range
Dim Ws As Worksheet
Set Sr = Selection.CurrentRegion
Set Ws = ActiveSheet
Ws.ListObjects.Add(SourceType:=xlSrcRange, Source:=Sr, XlListObjecthasheaders:=xlYes).Name = "XLnCAD"
End Sub
How to use codes shared here?