Sort on 2 Custom Lists

C

carusso

Hi all, I am trying to sort data by Column A first, and then Column B. Both
columns are custom lists. I tried this code but it will only read my custom
sort for Column A. Column B is sorted alphabetically ascending, not sorted
by my custom list. Any ideas? (the header will be "yes" later...that's why
it's there...)

Private Sub Workbook_Open()
Worksheets("Sheet1").Select
Cells.Select
Selection.Sort Key1:=Range("A1"), OrderCustom:=7, header:=xlNo, _
Key2:=Range("B1"), OrderCustom:=6, header:=xlNo
Sheet1.Activate
Range("A1").Select
Range("A1").Activate
End Sub

Thanks!
Cheryl
 
J

Jim Cone

Only one custom sort order is recognized per sort.
Run two separate sorts (using all data columns) - sort Column B then sort Column A.
--
Jim Cone
Portland, Oregon USA



"carusso"
<[email protected]>
wrote in message
Hi all, I am trying to sort data by Column A first, and then Column B. Both
columns are custom lists. I tried this code but it will only read my custom
sort for Column A. Column B is sorted alphabetically ascending, not sorted
by my custom list. Any ideas? (the header will be "yes" later...that's why
it's there...)

Private Sub Workbook_Open()
Worksheets("Sheet1").Select
Cells.Select
Selection.Sort Key1:=Range("A1"), OrderCustom:=7, header:=xlNo, _
Key2:=Range("B1"), OrderCustom:=6, header:=xlNo
Sheet1.Activate
Range("A1").Select
Range("A1").Activate
End Sub

Thanks!
Cheryl
 
C

carusso

OK, I thought I could figure this out...but not. I really don't know VBA,
just do a lot of copying and pasting and modifying. So can you please let me
know how to code 2 separate sorts.
Thanks!
 
J

Jim Cone

Two separate sorts, different key column and custom order in each...
'--
Sub MixEmUp()
Selection.Sort key1:=Range("B1"), ordercustom:=6, header:=xlNo, _
MatchCase:=False, Orientation:=xlTopToBottom
Selection.Sort key1:=Range("A1"), ordercustom:=7, header:=xlNo, _
MatchCase:=False, Orientation:=xlTopToBottom
End Sub
'--
The last sort determines the overall order of the data.
Jim Cone
Portland, Oregon USA



"carusso" <[email protected]>
wrote in message
OK, I thought I could figure this out...but not. I really don't know VBA,
just do a lot of copying and pasting and modifying.
So can you please let me know how to code 2 separate sorts.
Thanks!
 
C

carusso

ahhh..I still can't get it to work. Where exactly does your code go within
my code:

Private Sub Workbook_Open()
Worksheets("Sheet1").Select
Cells.Select
Selection.Sort Key1:=Range("A1"), OrderCustom:=7, header:=xlNo, _
Key2:=Range("B1"), OrderCustom:=6, header:=xlNo
Sheet1.Activate
Range("A1").Select
Range("A1").Activate
End Sub

Clueless Cheryl in VBA Land...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top