Demonstration script that opens an Excel spreadsheet and then sorts the data on column A (in ascending order), column B (descending order), and then column C (descending order). The script assumes that the worksheet includes a header row (indicated by xlYes, the last parameter in the Sort method). The script requires an Excel file named C:\Scripts\Sort_test.xls.

Visual Basic
Const xlAscending = 1
Const xlDescending = 2
Const xlYes = 1

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = _ 

Set objWorksheet = objWorkbook.Worksheets(1)
Set objRange = objWorksheet.UsedRange

Set objRange2 = objExcel.Range("A1")
Set objRange3 = objExcel.Range("B1")
Set objRange4 = objExcel.Range("C1")

objRange.Sort objRange2,xlAscending,objRange3,,xlDescending, _