Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
DCSwearingen
 
Posts: n/a
Default Using VBA To Sort Multiple Criteria


I know I have seen a similar question, but I did a search for "Sorting
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 errors


--
DCSwearingen

Getting old, but love computers.
------------------------------------------------------------------------
DCSwearingen's Profile: http://www.excelforum.com/member.php...o&userid=21506
View this thread: http://www.excelforum.com/showthread...hreadid=551157

  #2   Report Post  
Posted to microsoft.public.excel.misc
Chip Pearson
 
Posts: n/a
Default Using VBA To Sort Multiple Criteria

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"
wrote
in message
news:DCSwearingen.29azmo_1150139405.5059@excelforu m-nospam.com...

I know I have seen a similar question, but I did a search for
"Sorting
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 errors


--
DCSwearingen

Getting old, but love computers.
------------------------------------------------------------------------
DCSwearingen's Profile:
http://www.excelforum.com/member.php...o&userid=21506
View this thread:
http://www.excelforum.com/showthread...hreadid=551157



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
HLookup, IF statement, multiple sort, somehow combine all of these Gita at CASTLE Excel Worksheet Functions 0 May 2nd 06 07:43 PM
Multiple Criteria Rhiannons_Wish Excel Worksheet Functions 0 December 7th 05 06:32 PM
Multiple Criteria in SumProduct, N/A Result dcd123 Excel Worksheet Functions 7 October 7th 05 01:26 PM
COUNTIF or SUM function (Multiple criteria) HELP!! Australia Excel Worksheet Functions 3 September 19th 05 07:39 AM
Sum Multiple Criteria or DcountA rjenkins Excel Worksheet Functions 3 July 16th 05 12:21 AM


All times are GMT +1. The time now is 06:01 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"