Now let’s look at an example of sorting list data, but only for a pre-selected range of the list. As source data, we again use a table of cars and their owners.
On the worksheet, add a CommandButton control, and change its Caption property value to:
SORT ALL COLUMNS FOR THE SELECTED RANGE OF THE LIST.
Sorting list data by a selected range. Standard module
Sub SortColumnUp() Dim k As Long For k = Selection.Columns.Count To 1 Step -1 Selection.Sort Key1:=Selection.Cells(2, k), Order1:=xlAscending, _ Header:=xlGuess, Orientation:=xlTopToBottom Next k End Sub
Sorting list data by a selected range. Sheet1 module
Private Sub CommandButton1_Click() SortColumnUp End Sub