GunnRos86
GunnRos86

Reputation: 33

Sorting a Range of Data

This the code for sorting a range of data based on Column E values

Sub SortByLevel()

   ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
   ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add  Key:=Range("E13:E528" _
    ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal

   With ActiveWorkbook.Worksheets("Sheet1").Sort
      .SetRange Range("A12:L528")
      .Header = xlYes
      .MatchCase = False
      .Orientation = xlTopToBottom
      .SortMethod = xlPinYin
      .Apply
  End With

End Sub

Note that B12:L12 is the range of headers. I have the impression that this can be much more simpler than that. Any suggestions would be much appreciated. Thanks, Michael

Upvotes: 0

Views: 84

Answers (1)

Abdellah OUMGHAR
Abdellah OUMGHAR

Reputation: 3745

use this :

Range("A12:L528").Sort Key1:=Range("E13"), Order1:=xlAscending, Header:=xlYes

Upvotes: 2

Related Questions