I have the following macro that's supposed to sort all the tables on the worksheet named "Lists" but I keep getting an error at the line "For Each lo In ws". Can some please show me the error in my code? I'm open to a completely different code if it serves the purpose. Not sure it matters but there are currently 7 dynamic tables that have defined names. Thanks in advance for the help. Here's the code:
Sub Sort()
Dim lo As ListObject
Dim wb As Workbook: Set wb = ThisWorkbook
Dim ws As Worksheet
Set ws = wb.Sheets("Lists")
ws.Activate
For Each lo In ws
With lo.Sort
.SortFields.Clear
.SortFields.Add Key:=sortcolumn, SortOn:=xlSortOnValues, Order:=xlAscending
.Header = xlYes
.Apply
End With
Next lo
End Sub
Sub Sort()
Dim lo As ListObject
Dim wb As Workbook: Set wb = ThisWorkbook
Dim ws As Worksheet
Set ws = wb.Sheets("Lists")
ws.Activate
For Each lo In ws
With lo.Sort
.SortFields.Clear
.SortFields.Add Key:=sortcolumn, SortOn:=xlSortOnValues, Order:=xlAscending
.Header = xlYes
.Apply
End With
Next lo
End Sub