• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Sort by multiple columns

ysherriff

Member
Hi i have the below code to sort by multiple columns but for some reason it is not working. I do not get an error message but the code doesn't work. What am i missing?

Thanks for your help

Code:
With ActiveSheet.Sort
             .SortFields.Clear
             .SortFields.Add Key:=Range("D9:D700" _
                                   ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
             .SortFields.Add Key:=Range("J9:j700" _
                                   ), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
            .SetRange Range("B9:N700")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
End With
 
Hi ,

I have tried your code , and it works without any problem.

Can you upload your workbook with the data in it ?

Narayan
 
You can try this code instead
Code:
Sub SortData()
    With ActiveSheet
        .Range("B9:N700").Sort _
                Key1:=.Range("D9:D700"), Order1:=xlAscending, _
                Key2:=.Range("J9:j700"), Order2:=xlDescending, _
                Header:=xlYes
    End With
End Sub
 
Back
Top