Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Sorting - More than three columns?

Status
Not open for further replies.

sgreenwood

Technical User
May 7, 2001
48
US
Hi all,

I believe I already know the answer to this question, but I also know if I'm wrong, someone here will surely know it!

When sorting in Excel, is there ANY way to sort on more than three columns?? Without doing multiple sorts on ranges? I have many huge spreadsheets which need to be sorted sometimes by maybe five or six columns, and I can't find any easy way to do it.

Any help will be greatly appreciated.

Thanks,
Steve
 
Steve,

Some of us dinasaurs of the IT world either know of, have seen or have even used Hollereth Card (a.k.a. IBM Card) sorting machines.

I have been a "user"!

The rule is: Sort from the least significant to the most significant column. In a sorting machine, a 5-column sort required 5 sort passes.

In the case of Excel, to accomplish a 5-column sort will require 2 3-column sorts (well really a 2 and a 3). I would suggest that you Macro-record what you want to do and put the results in a single procedure that you could run in one swell foop (I mean, one fell swoop!)

1. Sort on columns 4 & 5

2. Sort on columns 1, 2 & 3

Here's an example of a sort on C & B, then D, A & K
Code:
Sub Sort5()
'
' Macro1 Macro
' Macro recorded 6/25/2002 by Skip
'

'
    Range("A1").CurrentRegion.Sort _
        Key1:=Range("C1"), Order1:=xlAscending, _
        Key2:=Range("B1"), Order2:=xlAscending, _
        Header:=xlNo, _
        OrderCustom:=1, _
        MatchCase:=False, _
        Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal, _
        DataOption2:=xlSortNormal
    Range("A1").CurrentRegion.Sort _
        Key1:=Range("D1"), Order1:=xlAscending, _
        Key2:=Range("A1"), Order2:=xlAscending, _
        Key3:=Range("K1"), Order3:=xlAscending, _
        Header:=xlNo, _
        OrderCustom:=1, _
        MatchCase:=False, _
        Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal, _
        DataOption2:=xlSortNormal
End Sub
Hope this helps :) Skip,
SkipAndMary1017@mindspring.com
 
Hi, Skip,

That tells your age.

Just like knowing what "answer is 42" means.

Indu
 
Hey, I'm only 26 and I'm still wondering what the question to the answer of life is.

Don't go there. [reading]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top