Sorting Table Record - MS-Excel Tutorial
Sorting Table Record
Sorting a table involves rearranging the rows so they are in ascending or descending order, based on the values in one or more columns. You may, for example, want to sort a table of salespeople alphabetically by last name or by sales region. You can sort numerically, alphabetically, or by date, depending on the data.
If you sort a filtered table, Excel sorts only the visible rows. After you remove the filtering from the table, the table is no longer sorted. Therefore, you should remove any column filters before sorting the table.
Never Forget: You need to re-sort your table after adding (and perhaps editing) table rows. To re-sort the table, click any cell in the table, click the Sort & Filter button in the Design tab and choose Reapply from the menu.
Sorting a single column based on column values
Follow these steps to sort a single column in your table based on the data in the table:
- Click the arrow on the header of the column you want to sort. Excel displays the filter and sort menu.
- Choose one of the sort direction options at the top of the menu. The options depend on the data type in the column you are sorting (numeric, text, or date). After you choose an option, Excel rearranges the rows in the table.
After you apply a sort to a column, Excel adds a small arrow to the column header arrow, indicating the direction of the sort. The arrow also serves as a reminder that you have applied a sort to the column.
The ability to sort by date order (that is, oldest to newest or newest to oldest) is new in Excel 2007.
Using the Sort dialog box
When you can't sort table information exactly the way you want by using the Sort A to Z and Sort Z to A buttons, use the Sort dialog box.
To use the Sort dialog box, follow these steps:
- Click a cell inside the table.
- Choose the Data> Sort command. Excel displays the Sort dialog box, as shown below.
- Select the first sort key. Use the Sort By drop-down list to select the field that you want to use for sorting. Next, choose what you want to use for sorting: values, cell colors, font colors, or icons. Probably, you are going to sort by values, in which case, you will also need to indicate whether you want records arranged in ascending or descending order by selecting either the ascending A to Z or descending Z to A entry from the Order box.
Ascending order, predictably, alphabetizes labels and arranges values in smallest-value-to-largest-value order. Descending order arranges labels in reverse alphabetical order and values in largest-value-to-smallestvalue order. If you sort by color or icons, you need to tell Excel how it should sort the colors by using the options that the Order box provides.
Typically, you want the key to work in ascending or descending order. However, you might want to sort records by using a chronological sequence, such as Sunday, Monday, Tuesday, and so on and so forth. To use one of these other sorting options, select the custom list option from the Order box and then choose one of these other ordering methods from the dialog box that Excel displays. - (Optional) Specify any secondary keys. If you want to sort records that have the same primary key with a secondary key, click the Add Level button and then use the next row of choices from the Then By drop-down lists to specify which secondary keys you want to use. If you add a level that you later decide you don't want or need, click the sort level and then click the Delete Level button. You can also duplicate the selected level by clicking Copy Level. Finally, if you do create multiple sorting keys, you can move the selected sort level up or down in significance by clicking the Move Up or Move Down buttons.
Remember: The Sort dialog box also provides a My Data Has Headers check box that enables you to indicate whether the worksheet range selection includes the row and field names. If you have already told Excel that a worksheet range is a table, however, this check box is disabled. - (optional) Fiddle-faddle with the sorting rules. If you click the Options button in the Sort dialog box, Excel displays the Sort Options dialog box. Make choices here to further specify how the first key sort order works.
case sensitivity (uppercase versus lowercase) should be considered. You can also use the Sort Options dialog box to tell Excel that it should sort rows instead of columns or columns instead of rows. You make this specification by using either Orientation radio button: Sort Top to Bottom or Sort Left to Right. Click OK when you have sorted out your sorting options. - Click OK. Excel then sorts your list.