Macro works fine when it is the only workbook open, but when any other workbook is open it fails. I am sure this is an easy fix but I can't figure it out. Thank you in advance.
Sub Sort_Leaders()
Dim wb As Workbook: Set wb = ThisWorkbook
wb.Worksheets("TABLE").ListObjects("Table1").Sort.SortFields.Clear
wb.Worksheets("TABLE").ListObjects("Table1").Sort.SortFields.Add _
Key:=Range("Table1[[#All],[Rank]]"), SortOn:=xlSortOnValues, Order:= _
xlAscending, DataOption:=xlSortNormal
With wb.Worksheets("TABLE").ListObjects("Table1").Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Call test
End Sub