Sort Method Example

This example sorts the range A1:C20 on Sheet1, using cell A1 as the first sort key and cell B1 as the second sort key. The sort is done in ascending order by row, and there are no headers.

Worksheets("Sheet1").Range("A1:C20").Sort _
    Key1:=Worksheets("Sheet1").Range("A1"), _
    Key2:=Worksheets("Sheet1").Range("B1")

This example sorts the region that contains cell A1 (the active region) on Sheet1, sorting by the data in the first column and automatically using a header row if one exists. The Sort method determines the active region automatically.

Worksheets("Sheet1").Range("A1").Sort _
    Key1:=Worksheets("Sheet1").Columns("A"), _
    Header:=xlGuess