View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
ozgrid.com ozgrid.com is offline
external usenet poster
 
Posts: 464
Default Sort by one column then another.

Assumes both Columns have headings

Sub SortAE()
Application.DisplayAlerts = False
'CODENAME
'http://www.ozgrid.com/VBA/excel-vba-sheet-names.htm
With Sheet1
.Range("B1", Cells(.Rows.Count, "B") _
.End(xlUp)).Sort .Range("B1"), xlAscending, , , , , , xlYes
.Range("E1", Cells(.Rows.Count, "E") _
.End(xlUp)).Sort .Range("E1"), xlAscending, , , , , , xlYes
End With
Application.DisplayAlerts = True
End Sub



--
Regards
Dave Hawley
www.ozgrid.com
"sort" wrote in message
...
I want to do two sorts one on column "B" and then by column "E" for a
specific range.

Below is the sort for the first sort. How do I do a nested sort along
whith
the below sort?

ActiveWorkbook.Worksheets("Sheet1").Sort.SortField s.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortField s.Add Key:=Range _
("B6:B100"), SortOn:=xlSortOnValues, Order:=xlAscending,
DataOption:= _
xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("A6:E100")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With