Data Sorting in Microsoft Excel
Sorting data is an integral part of data analysis. You might want to put a list of names in alphabetical order, compile a list of product inventory levels from highest to lowest, or order rows by colours or icons. Sorting data helps you quickly visualize and understand your data better, organize and find the data that you want, and ultimately make more effective decisions. To find the top or bottom values in a range of cells or table, such as top 10 grades or bottom 5 sales amounts, use AutoFilter or conditional formatting.
Sort data in a range or table
You can sort data by text (A to Z or Z to A), numbers (smallest to largest or largest to smallest), and dates and times (oldest to newest and newest to oldest) in one or more columns. You can also sort by a custom list (such as Large, Medium, and Small) or by format, including cell colour, font colour, or icon set. Most sort operations are column sorts, but you can also sort by rows.
Sort criteria are saved with the workbook so that you can reapply the sort each time that you open the workbook for an Excel table, but not for a range of cells. If you want to save sort criteria so that you can periodically reapply a sort when you open a workbook, then it's a good idea to use a table. This is especially important for multicolumn sorts or for sorts that take a long time to create.
In Excel 2007, you can apply sort states with up to sixty-four sort conditions to sort data by, but earlier versions of Excel support sort states with up to three conditions only. To avoid losing sort state information in earlier versions of Excel when the workbook is opened in an earlier version; you may want to change the sort state to one that uses no more than three conditions.
All sort state information remains available in the workbook, even after opening in an earlier version and is applied when the workbook is opened again in Excel 2007, unless the sort state information is edited in the earlier version of Excel.
Sort Text
- Select a column of alphanumeric data in a range of cells, or make sure that the active cell is in a table column containing alphanumeric data.
- On the Home tab, in the Editing group, and then click Sort & Filter.
- Do one of the following:
- To sort in ascending alphanumeric order, click Sort A to Z.
- To sort in descending alphanumeric order, click Sort Z to A.
- On the Home tab, in the Editing group, click Sort & Filter, and then click Custom Sort.
- In the Sort dialog box, click Options.
- In the Sort Options dialog box, select Case sensitive.
- Click OK twice.
- Ensure that all data is stored as text. If the column that you want to sort contains numbers stored as numbers and numbers stored as text, then you need to format them all as text. If you do not, the numbers stored as numbers are sorted before the numbers stored as text.
- To format all of the selected data as text, on the Home tab, in the Font group, click the Format Cell Font button, click the Number tab, and then under Category, click Text.
- Remove any leading spaces before sorting the data. In some cases, data imported from another application might have leading spaces inserted before data.
Sort Numbers
- Select a column of numeric data in a range of cells, or make sure that the active cell is in a table column containing numeric data.
- On the Home tab, in the Editing group, click Sort & Filter, and then do one of the following:
- To sort from low numbers to high numbers, click Sort Smallest to Largest.
- To sort from high numbers to low numbers, click Sort Largest to Smallest.
- Select a column of dates or times in a range of cells, or make sure that the active cell is in a table column containing dates or times.
- On the Home tab, in the Editing group, click Sort & Filter, and then do one of the following:
- To sort from an earlier to a later date or time, click Sort Oldest to Newest.
- To sort from a later to an earlier date or time, click Sort Newest to Oldest.
- Check that dates and times are stored as dates or times. If the results are not what you expected, the column might contain dates or times stored as text and not as dates or times. For Excel to sort dates and times correctly, all dates and times in a column must be stored as a date or time serial number. If Excel cannot recognize a value as a date or time, the date or time is stored as text. You can also see Section five on how to convert dates stored as text to dates.
- If you want to sort by days of the week, format the cells to show the day of the week. If you want to sort by the day of the week regardless of the date, convert them to text by using the TEXT function. However, the TEXT function returns a text value, and so the sort operation would be based on alphanumeric data.
- Select a column of data in a range of cells, or make sure that the active cell is in a table column.
- On the Home tab, in the Editing group, click Sort & Filter, and then click Custom Sort. The Sort dialog box is displayed.
- Under Column, in the Sort by box, select the column that you want to sort.
- Under Sort On, select the type of sort. Do one of the following:
- To sort by cell colour, select Cell Color.
- To sort by font colour, select Font Color.
- To sort by an icon set, select Cell Icon.
- Under Order, select how you want to sort. Do one of the following:
- To move the cell colour, font colour, or icon to the top or left, select On Top for a column sort, and On Left for a row sort.
- To move the cell colour, font colour, or icon to the bottom or right, select On Bottom for a column sort and On Right for a row sort.
- To specify the next cell colour, font colour, or icon to sort by, click Add Level, and then repeat steps four through five. Make sure that you select the same column in the Then by box and that you make the same selection under Order.
- Keep repeating steps five through six for each additional cell colour, font colour, or icon that you want included in the sort.
- Click Ok.
Check to ensure that all numbers are stored as number. If the results are not what you expected, the column might contain numbers stored as text and not as numbers. For example, negative numbers imported from some accounting systems or a number entered with a leading ' (apostrophe) are stored as text. For more information, see Convert numbers stored as text to numbers in Section five of this book.
No comments:
Post a Comment