Good morning,
I have a macro that, among other things, sorts a table in another workbook. Here's the relevant bits of code
Set wbLSHP = Workbooks("CDU_Enrollee Engagement Tracking Report v2.2.xlsx")
Set wsLSHP = wbLSHP.Worksheets("Sheet1")
"wsLSHP" is the worksheet where the table is located. The table is named "Table1"
wsLSHP.ListObjects("Table1").Sort.SortFields.Clear
wsLSHP.ListObjects("Table1").Sort.SortFields.add _
Key:=Range("Table1[[#All],[CHW First Name]]"), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
With wsLSHP.ListObjects("Table1").Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
When running this, I get the following error: "Run-time error '1004':, Application-defined or object-defined error
This happens at the following line:
wsLSHP.ListObjects("Table1").Sort.SortFields.add _
Key:=Range("Table1[[#All],[CHW First Name]]"), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
Any ideas on what's causing this error?