Sort by column D

Important Notice

Please note that on 14th December 2023 users will experience an expected outage whilst we make upgrades to our network. We anticipate this process may take a couple of hours and so we apologise in advance for any inconvenience.

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

    "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:

    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
        End With
  • Re: Sort by column D

    I believe you are missing some of the sort 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!