XL: Unexpected Results Using a Custom Sort OrderLast reviewed: February 2, 1998Article ID: Q151346 |
The information in this article applies to:
SYMPTOMS A custom sort order can be used to sort data in Microsoft Excel. A custom sort order can be used only as the first sort key. If the custom sort order is used with any key other than the first sort key, it is ignored.
RESOLUTIONTo use a custom sort order for a sort key other than the first sort key, the sorts must be performed separately. For example, if the custom sort order is the second sort key, run the sort procedure twice, using one sort key each time, instead of running the sort procedure once using two sort keys. First sort the data by using only one sort key (using a sort order that is built into Microsoft Excel). Then run the sort procedure again, by using only one sort key with a custom sort order. The following example shows how to do this.
Example
STATUSThis behavior is by design. The custom sort order is meant to be used with the first sort key only.
MORE INFORMATION
Macro ExampleMicrosoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:
http://www.microsoft.com/supportnet/refguide/ Sub Custom_Sorting() ' This runs the first sort proceudre, using the "normal" sort order. Range("A1:B8").Sort Key1:=Range("A2"), Order1:=xlAscending, _ Header:= xlYes, MatchCase:=False, Orientation:=xlTopToBottom ' This runs the second sort proceudre, using a custom sort order. Range("A1:B8").Sort Key1:=Range("B2"), Order1:=xlAscending, _ Header:= xlYes, OrderCustom:=6, MatchCase:=False, Orientation:= _ xlTopToBottom End SubNOTE: In the second sort procedure, the custom sort order is specified using the value 6. The value 6 is the index number given to the custom list (in the Custom List box under the Options on the Tools menu). To determine which index number has been assigned to your custom list, do the following:
For more information about Using a Custom Sort Order, click the Search button in Help and type:
custom sort order |
Additional query words:
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |