Using VBA To Sort Multiple Criteria

D

DCSwearingen

I know I have seen a similar question, but I did a search for "Sortin
Multiple Criteria" and did not find what I am looking for.

Is there a way to use VBA to sort by more than three criteria?

Specifically four criteria...

Example: The Header row is row 2

Selection.Sort _
Key1:=Range("E2"), Order1:=xlAscending, _
Key2:=Range("H2"), Order2:=xlAscending, _
Key3:=Range("B2"), Order3:=xlAscending, _
Header:=xlNo, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom

What the operators would like is

Selection.Sort _
Key1:=Range("A2"), Order1:=xlAscending, _
Key2:=Range("E2"), Order2:=xlAscending, _
Key3:=Range("H2"), Order3:=xlAscending, _
Key4:=Range("B2"), Order3:=xlAscending, _
Header:=xlNo, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom

but this creates error
 
C

Chip Pearson

You need to do two sorts. First sort on the least significant
columns (typically the right-most columns) then sort on the most
significant columns (typically the left-most columns).


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"DCSwearingen"
in message
news:D[email protected]...
 

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