I have 2 workbooks, workbook1 has all the macros, workbook2 has all the data.
I want to run the a macro in workbook1 to sort the data in workbook2 based on 4 criteria
But when i runned the macro it gave me Runtime error '1004' 
Rows("2:2").Select
Selection.AutoFilter
ActiveSheet.Range("$A$2:$" & colLetterTaxa & "$" & ActiveSheet.UsedRange.Rows.Count).AutoFilter Field:=numColTotalInst, _
Criteria1:=">=" & numInst, operator:=xlAnd
ActiveWorkbook.Worksheets(auxSheet).AutoFilter.Sort.SortFields.Clear
ActiveWorkbook.Worksheets(auxSheet).AutoFilter.Sort.SortFields.Add Key _
:=Range(colLetterTaxa & "3:" & colLetterTaxa & ActiveSheet.UsedRange.Rows.Count), SortOn:=xlSortOnValues, order:=xlAscending, _
DataOption:=xlSortNormal
ActiveWorkbook.Worksheets(auxSheet).AutoFilter.Sort.SortFields.Add Key _
:=Range(colLetterDesvpad & "3:" & colLetterDesvpad & ActiveSheet.UsedRange.Rows.Count), SortOn:=xlSortOnValues, _
order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets(auxSheet).AutoFilter.Sort.SortFields.Add Key _
:=Range(colLetterTaxa & "3:" & colLetterTaxa & ActiveSheet.UsedRange.Rows.Count), SortOn:=xlSortOnValues, order:=xlDescending, _
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets(auxSheet).AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
The code crashes when it reaches .Apply
I really dont know why this happens, please somebody help me !
Bookmarks