How do I reference a specific column within a Table without calling the table by name? I would like to replace ===> Range("Table1[CODER]") <=== with a reference to either the .Listobject index number or using the variable "tableName" that I defined, but I cannot figure out the syntax for either option.
Public Sub CreateTableAndSortYNG()
Dim tableName As String
With ActiveWorkbook.ActiveSheet
.ListObjects.Add(xlSrcRange, .UsedRange, , xlYes).Name = .Name & "_Table"
tableName = ActiveWorkbook.ActiveSheet.ListObjects(1).DisplayName
MsgBox tableName
.ListObjects(1).Sort.SortFields.Clear
.ListObjects(1).Sort.SortFields.Add Key:=Range("Table1[CODER]"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.ListObjects(1).Sort.SortFields.Add Key:=Range("Table1[TYPE]"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.ListObjects(1).Sort.SortFields.Add Key:=Range("Table1[DSCHG_DT]"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
End With
End Sub
CODER
going to be whatTableName
is? You can do.ListObjects(1).Sort.SortFields.Add Key:=Range("Table1[" & tableName & "]"), ...
- BruceWayne.ListObjects(1).Sort.SortFields.Add Key:=Range(tableName & "[CODER]"), _ ...
- BruceWayne