Finance

Charts

Statistics

Macros

Search

Sorting Data in a Selected Range with Excel VBA

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
0 0 votes
Évaluation de l'article
S’abonner
Notification pour
guest
0 Commentaires
Le plus ancien
Le plus récent Le plus populaire
Online comments
Show all comments
Facebook
Twitter
LinkedIn
WhatsApp
Email
Print
0
We’d love to hear your thoughts — please leave a commentx