Sort by column D

  • I am trying to sort in column "D" from cell "D9" to "Dmaxm". It gives me an error:


    Code
    "The sort reference is not valid.  Make sure that it's within the data you want to sort, and the first Sort By box isn't the same or blank."


    All the data is consecutive. Data is in each cell all the way to the last cell.


    Here is the sort program I am using:


    Code
    maxm = Sheets("Compare").Cells(Rows.Count, "D").End(xlUp).Row
        With ActiveWorkbook.Worksheets("Compare").Sort
            .SetRange Range("D9:D" & maxm)
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
  • Re: Sort by column D


    I believe you are missing some of the sort code:


    ex:


    Code
    ActiveWorkbook.Worksheets("compare").Sort.SortFields.Add Key:=Range("D2:D14") _
            , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!