ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sort Macro (2 levels) (https://www.excelbanter.com/excel-programming/410381-sort-macro-2-levels.html)

cgsteel

Sort Macro (2 levels)
 
The code below sorts column "A" but if I wanted to add a level to the sort
that would sort column "B".

How would I do that?

Range("data1").Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlNo

Thanks
Carlos


Gary Keramidas

Sort Macro (2 levels)
 
try something like this

With Range("data1")
.Sort Key1:=.Range("A1"), Order1:=xlAscending, Key2:=.Range("B1") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:=
_
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _
:=xlSortNormal
End With

--


Gary


"cgsteel" wrote in message
...
The code below sorts column "A" but if I wanted to add a level to the sort
that would sort column "B".

How would I do that?

Range("data1").Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlNo

Thanks
Carlos




Gary Keramidas

Sort Macro (2 levels)
 
2 things:

watch the word-wrap and this will work in xl2003 and later.

--


Gary


"cgsteel" wrote in message
...
The code below sorts column "A" but if I wanted to add a level to the sort
that would sort column "B".

How would I do that?

Range("data1").Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlNo

Thanks
Carlos





All times are GMT +1. The time now is 02:47 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com