none
Excel VBA Problem when executing sort RRS feed

  • Question

  • Hi, friends.

    I have a macro to sort data table in a sheet, but when executing the sort , occurs the Error 424, object is required.

    The command is:

    Range("S1:W20").Select
        ActiveWorkbook.Worksheets("CLASS").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("CLASS").Sort.SortFields.Add Key:=Range("T1:T20"), _
            SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
        ActiveWorkbook.Worksheets("CLASS").Sort.SortFields.Add Key:=Range("U1:U20"), _
            SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
        ActiveWorkbook.Worksheets("CLASS").Sort.SortFields.Add Key:=Range("V1:V20"), _
            SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("CLASS").Sort
            .SetRange Range("S1:W20")
            .Header = xlGuess
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With

    I'd like someone help me.

    Thanks.

    Sergio.

    Sunday, April 10, 2016 3:00 PM

Answers

All replies

  • On what line does the error occur?

    Best regards, George

    Sunday, April 10, 2016 3:17 PM
  • Works here although I do not have your data

    Best regards, George

    Sunday, April 10, 2016 3:25 PM
  • Hi, Smurakata

    >> I have tested your code at my side having the data in the sheet and also without data.

    >> code is working perfectly. Sorting is also done. Doesn’t give any error.

    >> kindly recheck the code again at your side.

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, April 11, 2016 8:17 AM
    Moderator
  • Hi, George.

    According to Deepak, the code was tested and worked without problem.

    And you did the same, also working well.

    I'll recheck the code and hope find the solution.

    Regards,

    Sergio.

    Monday, April 11, 2016 1:21 PM
  • Hi, Deepak.

    You tested my code successfully and so I have to reckeck it.

    Thanks for the answer.

    Regards,

    Sergio.

    Monday, April 11, 2016 1:31 PM