Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 516
Default Sort More than 3 criteria

Hi
I am trying to sort a data range with more than 3 criteria. I have tried
editing a recorded macro with 3 criteria and adding the 4th and it is not
working.

Selection.Sort Key1:=Range("C2"), Order1:=xlAscending, Key2:=Range("b2") _
, Order2:=xlAscending, Key3:=Range("D2"), Order3:=xlAscending,
Key4:=Range("h2"), _
Order1:=xlAscending, Header:=xlGuess, OrderCustom:=1,
MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal
End Sub

Is there an error in my code or do I need a different approach?
Thanks
Matt
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Sort More than 3 criteria

Hi
you have to do this in multiple steps:
1. Sort with the last criteria
2. Repeat sorting with the first 3 criteria

--
Regards
Frank Kabel
Frankfurt, Germany

Matt wrote:
Hi
I am trying to sort a data range with more than 3 criteria. I have
tried editing a recorded macro with 3 criteria and adding the 4th and
it is not working.

Selection.Sort Key1:=Range("C2"), Order1:=xlAscending,
Key2:=Range("b2") _ , Order2:=xlAscending, Key3:=Range("D2"),
Order3:=xlAscending, Key4:=Range("h2"), _
Order1:=xlAscending, Header:=xlGuess, OrderCustom:=1,
MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal
End Sub

Is there an error in my code or do I need a different approach?
Thanks
Matt



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 123
Default Sort More than 3 criteria

Sort method can take max. of 3 sort field (key) arguments.
You can first sort with 1 key, and then repeat again with 3 more keys.

Sharad



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
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
Sort Criteria STRAC Excel Discussion (Misc queries) 1 March 5th 08 02:06 PM
Saving sort criteria thouston Excel Discussion (Misc queries) 0 November 7th 07 02:56 PM
Saving Sort Criteria (or Sort Lists) Jim J. Excel Worksheet Functions 1 July 25th 06 10:55 AM
How do I get it to sort Criteria in A1:A6 and B1:B6 if both are c. C Cooper Midland Excel Discussion (Misc queries) 2 December 14th 04 09:55 PM
How to sort a sheet with more than three criteria Haldun Alay[_2_] Excel Programming 3 September 24th 03 10:00 AM


All times are GMT +1. The time now is 06:21 AM.

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"