|Excel And SQL .com|
Home > VBA Macros
How to sort a list of values in a column
Below example assumes you have a list of values in column A and the data has header in row one. so, to sort this list, you can use the following sort method of range object.
The example only shows how to use on columns, but you can use the same technique on any range also.
Sub Demo() 'First create some test data Cells(1,1) = "Student Name" cells(2,1) = "Jack" cells(3,1) = "Bob" cells(4,1) = "Zack" cells(5,1) = "Carly" cells(6,1) = "Mat" cells(7,1) = "Aaron" 'Now apply sort method to sort the data in column A, starting from row 2, row 1 contains the header. Columns("A:A").Sort key1:=Range("A2"), _ order1:=xlAscending, Header:=xlYes End Sub
|© All Rights Reserved. ExcelAndSql.com|