Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Sort using 4 keys

Is there an easy to sort using 4 keys.... I have sorting using 3 keys
working but cannot get 4 keys to work..... the code I use is:

Range(Cells(4, 1), Cells(endrow, 11)).Sort Key1:=Range("F4"),
Order1:=xlAscending, Key2:=Range( _
"C4"), Order2:=xlAscending, Key3:=Range("E4"), Order3:=xlAscending, _
header:=xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=
xlTopToBottom


this works fine, but if I add a 4th key:


Range(Cells(4, 1), Cells(endrow, 11)).Sort Key1:=Range("F4"),
Order1:=xlAscending, Key2:=Range( _
"C4"), Order2:=xlAscending, Key3:=Range("E4"),
Order3:=xlAscending,Key4:=Range("D4"), Order4:=xlAscending, _
header:=xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=
xlTopToBottom



Then I get compilation errors: "Named argument not found" and it
highlights "Key4"

Thanks
Chuck
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Sort using 4 keys

Chuck,

Two possibilities

1. Sort with the first 3 keys, and then sort again with the first 2 keys and
the 4th. Should work fine.

2. Concatenate key 3 and 4 and sort on key 1, key 2, and the composite key
3/4.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"ChuckM" wrote in message
. ..
Is there an easy to sort using 4 keys.... I have sorting using 3 keys
working but cannot get 4 keys to work..... the code I use is:

Range(Cells(4, 1), Cells(endrow, 11)).Sort Key1:=Range("F4"),
Order1:=xlAscending, Key2:=Range( _
"C4"), Order2:=xlAscending, Key3:=Range("E4"), Order3:=xlAscending, _
header:=xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=
xlTopToBottom


this works fine, but if I add a 4th key:


Range(Cells(4, 1), Cells(endrow, 11)).Sort Key1:=Range("F4"),
Order1:=xlAscending, Key2:=Range( _
"C4"), Order2:=xlAscending, Key3:=Range("E4"),
Order3:=xlAscending,Key4:=Range("D4"), Order4:=xlAscending, _
header:=xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=
xlTopToBottom



Then I get compilation errors: "Named argument not found" and it
highlights "Key4"

Thanks
Chuck



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Sort using 4 keys

This file might be a help:
http://www.bygsoftware.com/examples/...ColumnSort.zip

It's in the "Worksheet with VBA" section on page:
http://www.bygsoftware.com/examples/examples.htm

This workbook demonstrates a method to sort four or more columns.

--
Regards
Andy Wiggins
www.BygSoftware.com
Home of "Save and BackUp",
"The Excel Auditor" and "Byg Tools for VBA"



"ChuckM" wrote in message
. ..
Is there an easy to sort using 4 keys.... I have sorting using 3 keys
working but cannot get 4 keys to work..... the code I use is:

Range(Cells(4, 1), Cells(endrow, 11)).Sort Key1:=Range("F4"),
Order1:=xlAscending, Key2:=Range( _
"C4"), Order2:=xlAscending, Key3:=Range("E4"), Order3:=xlAscending, _
header:=xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=
xlTopToBottom


this works fine, but if I add a 4th key:


Range(Cells(4, 1), Cells(endrow, 11)).Sort Key1:=Range("F4"),
Order1:=xlAscending, Key2:=Range( _
"C4"), Order2:=xlAscending, Key3:=Range("E4"),
Order3:=xlAscending,Key4:=Range("D4"), Order4:=xlAscending, _
header:=xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=
xlTopToBottom



Then I get compilation errors: "Named argument not found" and it
highlights "Key4"

Thanks
Chuck



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 worksheet on multiple keys - Primary, secondary, tirterary, etc. Doug Mc New Users to Excel 12 October 22nd 09 02:18 AM
Updating workbook with an alpha sort sheet and a numeric sort shee cjlatta Excel Discussion (Misc queries) 2 January 28th 09 12:00 AM
Many Sort Keys [email protected] New Users to Excel 13 August 3rd 07 01:08 AM
VBA Sort method w/more than 3 Keys KenRoy Excel Discussion (Misc queries) 1 August 26th 05 10:48 PM
Dynamically set Sort keys Wilbur[_3_] Excel Programming 4 October 21st 03 09:21 PM


All times are GMT +1. The time now is 09:52 PM.

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

About Us

"It's about Microsoft Excel"