1. Welcome to Chandoo.org Forums. Short message for you

    Hi Guest,

    Thanks for joining Chandoo.org forums. We are here to make you awesome in Excel. Before you post your first question, please read this short introduction guide. When posting or responding to questions please remember our values at Chandoo.org are: Humility, Passion, Fun, Awesomeness, Simplicity, Sharing Remember that we have people here for whom English is not there first language and we need to allow for this in our dealings.

  2. 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


  3. 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

Discussion in 'VBA Macros' started by ysherriff, Mar 19, 2017.

  1. ysherriff

    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 (vb):

    With ActiveSheet.Sort
                 .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
    End With
  2. NARAYANK991

    NARAYANK991 Excel Ninja

    Hi ,

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

    Can you upload your workbook with the data in it ?

  3. YasserKhalil

    YasserKhalil Active Member

    You can try this code instead
    Code (vb):
    Sub SortData()
        With ActiveSheet
            .Range("B9:N700").Sort _
                    Key1:=.Range("D9:D700"), Order1:=xlAscending, _
                    Key2:=.Range("J9:j700"), Order2:=xlDescending, _
        End With
    End Sub
    Thomas Kuriakose likes this.

Share This Page