chickflick91
chickflick91

Reputation: 63

is it possible to use VBA code to sort a range within a range?

I know how to sort a range by value. I have this code

Sub calander4()
Range("currentmonth").Sort _
Key1:=Range("currentmonthrating"), Order1:=xlDescending
End Sub

this code sorts range within columns highest to lowest by value. what i want on top of that is to sort the columns them selves left to right by a value. say the second top cell. which i would of course name and make range. is it possible?

Upvotes: 0

Views: 79

Answers (1)

user4039065
user4039065

Reputation:

You need to specify the Orientation parameter.

Option Explicit

Sub calander5()
    With Range("currentmonth")
        .Sort Key1:=.Cells(2, 1), Order1:=xlAscending, _
              Orientation:=xlSortColumns, Header:=xlNo
    End With
End Sub

See Range.Sort Method (Excel) for more.

Upvotes: 1

Related Questions