Article ID: 322067 - Last Review: February 1, 2007 - Revision: 2.5 How to correctly sort alphanumeric data in ExcelThis article was previously published under Q322067 On This PageSUMMARY
This article provides two methods that you can use to sort alphanumeric data (data that contains alphabetical letters mixed with numbers and special characters) in Microsoft Excel so that you achieve the results that you want. This article also provides a troubleshooting section. MORE INFORMATION
When you sort a column that contains alphanumeric characters, the sort may return unexpected results. Excel sorts the values left to right, character by character. For example, if a cell contains the text "A100," Excel places the cell after a cell that contains the entry "A1" and before a cell that contains the entry "A11." Excel sorts data in the following order:
0 1 2 3 4 5 6 7 8 9 (space) ! " # $ % & ( ) * , . / : ; ? @ [ \ ] ^ _ ` { | } ~ + < = > A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
For example, if you use Excel to sort the following column of data a1 a2 a3 1 1a 2 2a 3 3a 1 2 3 1a 2a 3a a1 a2 a3 To correctly format and sort alphanumeric dataFormat data by using the TEXT functionIf you format data by using the TEXT function, Excel converts the values to text in a specific number format.The syntax for the TEXT function is TEXT(value ,format_text)
where value is a numeric value, or a formula that evaluates to a numeric value, or
a reference to a cell that contains a numeric value; and format_text is a number format in text form from the Category box on the Number tab in the Format Cells dialog box.NOTE: Formatting a cell with an option on the Number tab (Cells command, Format menu) changes only the format, not the value. Using the TEXT function converts a value to formatted text, and the result is no longer calculated as a number. Examples of how to use the TEXT function are: =TEXT(2.715, "$0.00") equals "$2.72".
For example, follow these steps to format the data in column A of your worksheet by using the TEXT function:
=TEXT("4/15/91", "mmmm dd, yyyy") equals "April 15, 1991".
Troubleshoot sortingTo troubleshoot sorting problems, check the following points.Check the default sort order rulesExcel sorts data according to specific sort order rules. In an ascending sort, Excel uses the following order. (In a descending sort, this sort order is reversed except for blank cells, which are always placed last.)Numbers - Excel sorts numbers from the smallest negative number to the largest positive number. Alphanumeric - Excel sorts alphanumeric text left to right, character by character. See the beginning of the "More Information" section for complete information about alphanumeric sorts. Logical Values - Excel places FALSE before TRUE. Error Values - Excel treats all error values as equals. Blanks - Excel always places blanks last. Make sure that numbers are in a numeric formatIf Excel incorrectly sorts a cell that contains a value, the cell might be formatted as text and not as a number. For example, negative numbers from some accounting systems become text when the accounting data is imported into Excel. To convert a range of numbers that are stored as text to numbers, follow these steps:
Make sure that mixed data is formatted as textIf the column that you want to sort contains both numbers and numbers that include text characters (such as 100, 100a, 200, 200a), format them all as text. If you do not, Excel sorts the numbers first, and then sorts the numbers that include text characters.To format a number as text, follow these steps:
Make sure that dates and times are formatted correctlyExcel treats dates and times as numbers. When you type a date or time that Excel recognizes, the cell's format changes from the General number format to a built-in date or time format.For Excel to sort correctly, all dates and times in a column must use a date or time format. If Excel cannot recognize a value as a date, time, or number, the value is formatted as text. To apply the correct formatting, follow these steps:
Unhide rows and columns before you sortHidden rows are not moved when you sort rows, and hidden columns are not moved when you sort columns. However, when you sort rows, the data in hidden columns is sorted, and when you sort columns, the data in hidden rows is sorted. Before you sort the list, unhide the hidden rows and columns.Remove any leading spacesIn some cases, data that was imported from another program contains leading spaces. Remove the leading spaces before you sort the data.Enter column labels in only one rowIf you need multiple line labels, wrap the text in the cell.Check the settings for graphic objectsThe objects' settings may have been changed so that the objects do not move with cells. To set objects so that they can be sorted with cells, follow these steps:
REFERENCES
For more information about using a macro to sort columns, click the following article number to view the article in the Microsoft Knowledge Base:
247311
(http://support.microsoft.com/kb/247311/
)
How to use macros to sort data in multiple columns as one column in Excel
| Article Translations
|

Back to the top
