Below code to sort data with header ascending or descending. For example data with 3 columns.
Option Explicit
Sub ToSortWithOutHeader()
Range("A2:C6").Select
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, _
Key2:=Range("B2"), Order2:=xlAscending, _
Key3:=Range("C2"), Order3:=xlAscending, _
Header:=xlNo, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, _
DataOption2:=xlSortNormal, DataOption3:=xlSortNormal
Range("A1").Select
End Sub
Sub ToSortWithOutHeader()
Range("A2:C6").Select
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, _
Key2:=Range("B2"), Order2:=xlAscending, _
Key3:=Range("C2"), Order3:=xlAscending, _
Header:=xlNo, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, _
DataOption2:=xlSortNormal, DataOption3:=xlSortNormal
Range("A1").Select
End Sub
Note: Selection must include header and for Descending just change xlAscending to xlDescending.
No comments:
Post a Comment