2
votes

I'm trying to adapt an xla add-in that I wrote for Excel 2007 to work in Excel 2003. I have most of the issues sorted, but I'm having trouble finding a way to sort fields in a sheet. I have rows of data which need to be sorted in order of creation date (the value of which is in column H). Here's the Excel 2007 code I was using:

        'sort issues into descending order
        Sheets("In Progress").Sort.SortFields.Clear
        Sheets("In Progress").Sort.SortFields.Add _
                Key:=Range("H:H"), _
                SortOn:=xlSortOnValues, _
                Order:=xlDescending, _
                DataOption:=xlSortNormal
        With Sheets("In Progress").Sort
            .SetRange Range("A2:M" & rowCount - 1)
            .Header = xlNo
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With

Can anybody help me to get this to work with Excel 2003?

1
what error do you get? what doesn't work? did you try to remove step by step some lines of code? - JMax

1 Answers

3
votes

The best way is to write the code in lower version so that it works in all versions.

I would use this code for sorting which will work in all versions.

With Sheets("In Progress")
    .Range("A2:M" & rowCount - 1).Sort Key1:=.Range("A2"), _
    Order1:=xlDescending, Header:=xlNo, _
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal
End With