Okay all, I'm just having trouble figuring out the syntax for this. I know if you have a table called "Table1" whose first column is headed "Column1", you can sort it by doing the following:
With Table1
.Sort.SortFields.Add Range("Table1[[#All],[Column1]]"), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortTextAsNumbers
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
How do you use this syntax if you have only identified the table with a variable? The code I'm using identifies a worksheet based on a selection on the worksheet called "Dashboard", then identifies the table on that worksheet and setting a variable to it. Here's how I wrote that code:
Dim Part As String: Part = Dashboard.Range("B7").Value
Dim ws As Worksheet: Set ws = ActiveWorkbook.Worksheets(Part)
Dim tbl As ListObject: Set tbl = ws.ListObjects(1)
So now I want to sort the table that is identified by the variable "tbl". But how do I rewrite the code for that? I've tried this:
With Table1
.Sort.SortFields.Add Range(tbl"[[#All],[Column1]]"), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortTextAsNumbers
End With
...and this...
.Add Range("tbl[[#All],[Column1]]"), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortTextAsNumbers
...and this...
.Add Range(tbl[[#All],[Column1]]), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortTextAsNumbers
So now I'm at a loss. How do I do this?
Bookmarks