brWHigino
brWHigino

Reputation: 260

ActiveSheet.AutoFilter.Sort.SortFields.Clear in Excel 2003

I have a macro that works in Excel 2013, but the following part of the code breaks when running the macro in Excel 2003:

Sheets("dados").Select
Range("A1").AutoFilter Field:=6, Criteria1:="<>"
ActiveSheet.AutoFilter.Sort.SortFields.Clear
ActiveSheet.AutoFilter.Sort.SortFields.Add Key:=Range("A1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveSheet.AutoFilter.Sort.Apply

I wasn't able to find a clear reason why it is breaking. I read people mentioning the problem is the Sort object, but didn't find any replacement options. Is there a replacement for this filtering procedure which would work in Excel 2003?

I appreciate any help.

Upvotes: 3

Views: 44255

Answers (1)

Dmitry Pavliv
Dmitry Pavliv

Reputation: 35863

Try this one:

With ThisWorkbook.Sheets("dados")
    .Range("A1").AutoFilter Field:=6, Criteria1:="<>"

    .Range("A1").CurrentRegion.Sort Key1:=.Range("A1"), Order1:=xlAscending, _
        Header:=xlYes, OrderCustom:=1, DataOption1:=xlSortNormal
End With

Upvotes: 3

Related Questions