Excel.Tips.Net ExcelTips (Menu Interface)

Performing Complex Sorts

Summary: One way you can easily work with data in a worksheet is to sort it into whatever order you find most helpful. Excel allows you to perform sorting based on the criteria you determine, as discussed in this tip. (This tip works with Microsoft Excel 97, Excel 2000, Excel 2002, Excel 2003, and Excel 2007.)

By using the sorting capabilities of Excel you can perform complex sorting of either an entire list or any portion of a list. If you want to sort an entire list, you only need to select a single cell within the list. If you want to sort a portion of a list, you need to select those rows (they must be contiguous) that you want sorted.

  1. Display the Sort dialog box. (Click here to see a related figure.) In Excel 2007 display the Data tab of the Ribbon and then click on the Sort tool. In versions of Excel prior to 2007 choose the Sort option from the Data menu. Using this dialog box, sorting is performed according to criteria you set.
  2. Use the Sort By drop-down to select the field (or column) by which you want to sort.
  3. Use the subsequent Then By areas to specify secondary sorting keys. (In Excel 2007 you click Add Level each time you want to specify a secondary sorting key.)
  4. Specify for each sorting key whether you want that field to be sorted in ascending or descending order.
  5. Click the Options button to display the Sort Options dialog box (Click here to see a related figure.) where you can specify whether you want capitalization to matter and whether you want to sort rows or columns.
  6. Click on OK to close the Sort Options dialog box.
  7. Click on OK to complete your sort.

The First Key Sort Order option (from the Sort Options dialog box, step 5, in versions of Excel prior to Excel 2007) probably needs explanation. You will rarely need to change the value of this field. There will be times, however, when you will want to make changes. For instance, your primary sorting key might contain days of the week (Monday, Tuesday, Wednesday, and so on), and you want them to sort in proper chronological order. This is one of the sort orders you can specify in this field. You should pick a First Key Sort Order that most closely matches the needs of your data.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2919) applies to Microsoft Excel versions: 97 | 2000 | 2002 | 2003 | 2007

Related Tips:

Save Time! ExcelTips has been published weekly since late 1998. Past issues of ExcelTips are available in convenient ExcelTips archives. Have your own enhanced archive of ExcelTips at your fingertips, available to use at any time! Check out ExcelTips Archives today!