Please help. I cannot get this macro to work.... I am trying to sort by the active table, criteria is column 1. Then I would like to add a second critera, column 5 of the table. I keep getting an error on the line...
".Sort.SortFields.Add Key:=Range([activeTable("Column1")]), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal"
HERE IS THE CODE:
Sub SortActiveTable()
Dim ws As Worksheet
Dim tbl As ListObject
Dim activeTable As String
Set ws = ActiveSheet
activeTable = ActiveCell.ListObject.Name
Set tbl = ws.ListObjects(activeTable)
With tbl
.Sort.SortFields.Clear
.Sort.SortFields.Add Key:=Range([activeTable("Column1")]), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.Sort.Apply
End With
End Sub
".Sort.SortFields.Add Key:=Range([activeTable("Column1")]), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal"
HERE IS THE CODE:
Sub SortActiveTable()
Dim ws As Worksheet
Dim tbl As ListObject
Dim activeTable As String
Set ws = ActiveSheet
activeTable = ActiveCell.ListObject.Name
Set tbl = ws.ListObjects(activeTable)
With tbl
.Sort.SortFields.Clear
.Sort.SortFields.Add Key:=Range([activeTable("Column1")]), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.Sort.Apply
End With
End Sub