You are on page 1of 17

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 colors 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. NOTE 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. For more information, see Filter data in a range or table and Add, change, or clear conditional formats. 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 color, font color, 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. When you reapply a sort, different results appear for the following reasons: Data has been added, modified, or deleted to the range of cells or table column. Values returned by a formula have changed and the worksheet has been recalculated\ 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. 1. On the Data tab, in the Sort & Filter group, do one of the following: 2. To sort in ascending alphanumeric order, click Sort A to Z.

3. To sort in descending alphanumeric order, click Sort Z to A. 4. Optionally, you can do a case-sensitive sort. 5. How to sort by case-sensitivity 6. On the Data tab, in the Sort & Filter group, click Sort.

7. 8. 9. 10. 11.

In the Sort dialog box, click Options. In the Sort Options dialog box, select Case sensitive. Click OK twice. To reapply a sort after you change the data, click a cell in the range or table, and then on the Data tab, in the Sort & Filter group, click Reapply.

Sort numbers

1. 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. 2. On the Data tab, in the Sort & Filter group, do one of the following: 3. To sort from low numbers to high numbers, click 4. To sort from high numbers to low numbers, click Sort Smallest to Largest. Sort Largest to Smallest.

Sort dates or times

1. 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. 2. Select a column of dates or times in a range of cells or table. 3. On the Data tab, in the Sort & Filter group, do one of the following: y To sort from an earlier to a later date or time, click Sort Oldest to Newest.

y To sort from a later to an earlier date or time, click Sort Newest to Oldest. 4. To reapply a sort after you change the data, click a cell in the range or table, and then on the Data tab, in the Sort & Filter group, click Reapply. 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. For more information, see Show dates as days of the week.
NOTE

Sort by cell color, font color, or icon If you have manually or conditionally formatted a range of cells or table column, by cell color or font color, you can also sort by these colors. You can also sort by an icon set created through a conditional format. y y Select a column of data in a range of cells, or make sure that the active cell is in a table column. On the Data tab, in the Sort & Filter group, click 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 color, select Cell Color. To sort by font color, select Font Color. To sort by an icon set, select Cell Icon. Under Order, click the arrow next to the button, and then, depending on the type of format, select a cell color, font color, or cell icon. y Under Order, select how you want to sort. Do one of the following:  To move the cell color, font color, 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 color, font color, or icon to the bottom or right, select On Bottom for a column sort, and On Right for a row sort. y y    y There is no default cell color, font color, or icon sort order. You must define the order that you want for each sort operation.
NOTE

y y y y

To specify the next cell color, font color, or icon to sort by, click Add Level, and then repeat steps three 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 for each additional cell color, font color, or icon that you want included in the sort. To reapply a sort after you change the data, click a cell in the range or table, and then on the Data tab, in the Sort & Filter group, click Reapply.

Sort by a custom list

You can use a custom list to sort in a user-defined order. Excel provides built-in, day-of-the-week and month-of-the year custom lists, and you can also create your own custom list. 1. Optionally, create the custom list. How to create a custom list  In a range of cells, enter the values that you want to sort by, in the order that you want them, from top to bottom. For example:
A 1 2 3 High Medium Low

 Select the range that you just typed. In the example above, you would select cells A1:A3.  Click the Microsoft Office Button , click Excel Options, click the Popular category, and then under Top options for working with Excel, click Edit Custom Lists.  In the Custom Lists dialog box, click Import, and then click OK twice. Notes
y y

You can only create a custom list based on a value (text, number, and date or time). You cannot create a custom list based on a format (cell color, font color, and icon). The maximum length for a custom list is 255 characters, and the first character must not begin with a number.

2. Select a column of data in a range of cells, or make sure that the active cell is in a table column. 3. On the Data tab, in the Sort & Filter group, click Sort.

The Sort dialog box is displayed.

4. Under Column, in the Sort by or Then by box, select the column that you want to sort by a custom list. 5. Under Order, select Custom List. 6. In the Custom Lists dialog box, select the list that you want. In the preceding example, you would click High, Medium, Low. 7. Click OK. 8. To reapply a sort after you change the data, click a cell in the range or table, and then on the Data tab, in the Sort & Filter group, click Reapply. Sort rows 1. Select a row of data in a range of cells, or make sure that the active cell is in a table column. 2. On the Data tab, in the Sort & Filter group, click Sort.

The Sort dialog box is displayed.

1. 2. 3. 4.

Click Options. In the Sort Options dialog box, under Orientation, click Sort left to right, and then click OK. Under Column, in the Sort by box, select the row that you want to sort. Do one of the following:

By value 1. 2. y y y Under Sort On, select Values. Under Order, do one of the following: For text values, select A to Z or Z to A. For number values, select Smallest to Largest or Largest to Smallest. For date or time values, select Oldest to Newest or Newest to Oldest.

By cell color, font color, or cell icon 1. Under Sort On, select Cell Color, Font Color, or Cell Icon. 2. Click the arrow next to the button, and then select a cell color, font color, or cell icon. 3. Under Order, select On Left or On Right. 4. To reapply a sort after you change the data, click a cell in the range or table, and then on the Data tab, in the Sort & Filter group, click Reapply.

NOTE

When you sort rows that are part of a worksheet outline, Excel sorts the highest-level groups (level 1) so

that the detail rows or columns stay together, even if the detail rows or columns are hidden.

Sort by more than column or row


You might sort by more than one column or row when you have data that you want to group by the same value in one column or row, and then sort another column or row within that group of equal values. For example, if you have a Department and Employee column, you can first sort by Department (to group all the employees in the same department together), and then sort by name (to put the names in alphabetical order within each department). You can sort by up to 64 columns.

NOTE

For best results, the range of cells that you sort should have column headings.

1.

Select a range of cells with two or more columns of data, or make sure that the active cell is in a table with two or more columns.

2.

On the Data tab, in the Sort & Filter group, click Sort.

The Sort dialog box is displayed.

3. 4.

Under Column, in the Sort by box, select the first column that you want to sort. Under Sort On, select the type of sort. Do one of the following:

To sort by text, number, or date and time, select Values.


5.

To sort by format, select Cell Color, Font Color, or Cell Icon. Under Order, select how you want to sort. Do one of the following:

   
6. 7. 8.

For text values, select A to Z or Z to A. For number values, select Smallest to Largest or Largest to Smallest. For date or time values, select Oldest to Newest or Newest to Oldest. To sort based on a custom list, select Custom List. To add another column to sort by, click Add Level, and then repeat steps three through five. To copy a column to sort by, select the entry, and then click Copy Level. To delete a column to sort by, select the entry, and then click Delete Level.

NOTE

You must keep at least one entry in the list.

9.

To change the order in which the columns are sorted, select an entry, and then click the Up or Down arrow to change the order.

Entries higher in the list are sorted before entries lower in the list.

10. To reapply a sort after you change the data, click a cell in the range or table, and then on the Data tab, in the Sort & Filter group, click Reapply.

Sort by a partial value in a column


Sorting is based on the entire value in a column. If you want to sort by part of a value in a column, such as a part number code (789-WDG-34), last name (Carol Philips), or first name (Philips, Carol), you first need to split the column into two or more columns so that the value you want to sort by is in its own column. To do this, you can use functions or the Convert Text to Columns Wizard.

For examples and more information, see Split names by using the Convert Text to Columns Wizard and Split text among columns by using functions.

Top of Page

Sort one column in a range of cells without affecting the others


WARNING Be careful when using this feature. Sorting by one column in a range may produce results that you don't

want, such as moving cells in that column away from other cells in the same row.

NOTE

You cannot do the following procedure in a table.

1.

Select a column in a range of cells containing two or more columns.

2. 3.

To select the column that you want to sort, click the column heading. On the Home tab, in the Editing group, click Sort & Filter, and then click one of the available sort commands.

4.

The Sort Warning dialog box is displayed.

5. 6. 7.

Select Continue with the current selection. Click Sort. Select any other sort options that you want in the Sort dialog box, and then click OK.

If the results are not what you want, click Undo

Top of Page

Learn more about general issues with sorting


If you get unexpected results when sorting your data, do the following:

Check to see if the values returned by a formula have changed If the data that you have sorted contains one or more formulas, the return values of those formulas can change when the worksheet is recalculated. In this case, make sure that you reapply the sort or do the sort again to get up-to-date results.

Unhide rows and columns before you sort Hidden columns are not moved when you sort columns, and hidden rows are not moved when you sort rows. Before you sort data, it's a good idea to unhide the hidden columns and rows.

Check the locale setting Sort orders vary by locale setting. Make sure that you have the proper locale setting in Regional Settings or Regional and Language Options in Control Panel on your computer. For information about changing the locale setting, see the Windows help system.

Enter column headings in only one row If you need multiple line labels, wrap the text within the cell.

Turn on or off the heading row It's usually best to have a heading row when you sort a column to make it easier to understand the meaning of the data. By default, the value in the heading is not included in the sort operation. Occasionally, you may need to turn on or off the heading so that the value in the heading is or is not included in the sort operation. Do one of the following:

To exclude the first row of data from the sort because it is a column heading, on the Home tab, in the Editing group, click Sort & Filter, click Custom Sort, and then select My data has headers. To include the first row of data in the sort because it is not a column heading, on the Home tab, in the Editing group, click Sort & Filter, click Custom Sort, and then clear My data has headers.

Filter data in a range or table


Show All

Using AutoFilter to filter data is a quick and easy way to find and work with a subset of data in a range of cells or table. Once you have filtered data in a range of cells or table, you can either reapply a filter to get up-to-date results, or clear a filter to redisplay all of the data.

Learn more about filtering


Filtered data displays only the rows that meet criteria that you specify and hides rows that you do not want displayed. After you filter data, you can copy, find, edit, format, chart, and print the subset of filtered data without rearranging or moving it.

You can also filter by more than one column. Filters are additive, which means that each additional filter is based on the current filter and further reduces the subset of data.

NOTE

When you use the Find dialog box to search filtered data, only the data that is displayed is searched; data

that is not displayed is not searched. To search all the data, clear all filters.

The three types of filters


Using AutoFilter, you can create three types of filters: by a list values, by a format, or by criteria. Each of these filter types is mutually exclusive for each range of cells or column table. For example, you can filter by cell color or by a list of numbers, but not by both; you can filter by icon or by a custom filter, but not by both.

Reapplying a filter
To determine if a filter is applied, note the icon in the column heading:

A drop-down arrow

means that filtering is enabled but not applied.

TIP When you hover over the heading of a column with filtering enabled but not applied, a screen tip

displays "(Showing All)".

A Filter button

means that a filter is applied.

TIP When you hover over the heading of a filtered column, a screen tip displays the filter applied to that

column, such as "Equals a red cell color" or "Larger than 150".

When you reapply a filter, different results appear for the following reasons:

Data has been added, modified, or deleted to the range of cells or table column. The filter is a dynamic date and time filter, such as Today, This Week, or Year to Date. Values returned by a formula have changed and the worksheet has been recalculated.

Do not mix storage formats


For best results, do not mix storage formats, such as text and number or number and date, in the same column because only one type of filter command is available for each column. If there is a mix of storage formats, the

command that is displayed is the storage format that occurs the most. For example, if the column contains three values stored as number and four as text, the filter command that is displayed is Text Filters. For more information, see Convert numbers stored as text to numbers and Convert dates stored as text to dates.

Top of Page

Filter text
1. Do one of the following:

Range of cells

1. 2.

Select a range of cells containing alphanumeric data. On the Data tab, in the Sort & Filter group, click Filter.

Table

Make sure that the active cell is in a table column that contains alphanumeric data. Click the arrow in the column header.

Do one of the following:

Select from a list of text values

In the list of text values, select or clear one or more text values to filter by.

The list of text values can be up to 10,000. If the list is large, clear (Select All) at the top, and then select the specific text values to filter by.

TIP To make the AutoFilter menu wider or longer, click and drag the grip handle at the bottom.

Create criteria

1.

Point to Text Filters and then click one of the comparison operator commands, or click Custom Filter.

For example, to filter by text that begins with a specific character, select Begins With, or to filter by text that has specific characters anywhere in the text, select Contains.

2.

In the Custom AutoFilter dialog box, in the box on the right, enter text or select the text value from the list.

For example, to filter by text that begins with the letter "J", enter J, or to filter by text that has "bell" anywhere in the text, enter bell.

If you need to find text that shares some characters but not others, use a wildcard character.

How to use wildcard characters

Use ? (question mark)

To find Any single character For example, sm?th finds "smith" and "smyth" Any number of characters For example, *east finds "Northeast" and "Southeast" A question mark, asterisk, or tilde For example, fy06~? finds "fy06?"

* (asterisk)

~ (tilde) followed by ?, *, or ~

3.

Optionally, filter by one more criteria.

How to add one more criteria

1.

Do one of the following:

 
2.

To filter the table column or selection so that both criteria must be true, select And. To filter the table column or selection so that either or both criteria can be true, select Or. In the second entry, select a comparison operator, and then in the box on the right, enter text or select a text value from the list.

To reapply a filter after you change the data, click a cell in the range or table, and then on the Data tab, in the Sort & Filter group, click Reapply.

Top of Page

Filter numbers
1. Do one of the following:

Range of cells

1. 2.

Select a range of cells containing numeric data. On the Data tab, in the Sort & Filter group, click Filter.

Table

Make sure that the active cell is in a table column that contains numeric data.

Click the arrow

in the column header.

Do one of the following:

Select from a list of numbers

In the list of numbers, select or clear one or more numbers to filter by.

The list of numbers can be up to 10,000. If the list is large, clear (Select All) at the top, and then select the specific numbers to filter by.

TIP To make the AutoFilter menu wider or longer, click and drag the grip handle at the bottom.

Create criteria

1.

Point to Number Filters and then click one of the comparison operator commands or click Custom Filter.

For example, to filter by a lower and upper number limit, select Between.

2.

In the Custom AutoFilter dialog box, in the box or boxes on the right, enter numbers or select numbers from the list.

For example, to filter by a lower number of 25 and an upper number of 50, enter 25 and 50.

3.

Optionally, filter by one more criteria.

How to add one more criteria

1.

Do one of the following:

 
2.

To filter the table column or selection so that both criteria must be true, select And. To filter the table column or selection so that either or both criteria can be true, select Or. In the second entry, select a comparison operator, and then in the box on the right, enter a number or select a number from the list.

To reapply a filter after you change the data, click a cell in the range or table, and then on the Data tab, in the Sort & Filter group, click Reapply.

Top of Page

Filter dates or times


1. Do one of the following:

Range of cells

1.

Select a range of cells containing numeric data.

2.

On the Data tab, in the Sort & Filter group, click Filter.

Table

Make sure that the active cell is in a table column that contains dates or times. Click the arrow in the column header.

Do one of the following:

Select from a list of dates or times

In the list of dates or times, select or clear one or more dates or times to filter by.

By default, all dates in the range of cells or table column are grouped by a hierarchy of years, months, and days. Selecting or clearing a higher level in the hierarchy selects or clears all nested dates below that level. For example, if you select 2006, months are listed below 2006, and days are listed below each month.

The list of values can be up to 10,000. If the list of values is large, clear (Select All) at the top, and then select the values to filter by.

TIP To make the AutoFilter menu wider or longer, click and drag the grip handle at the bottom.

Create criteria

1.

Point to Date Filters and then do one of the following:

Common filter

NOTE

A common filter is one based on a comparison operator.

1.

Click one of the comparison operator commands (Equals, Before, After, or Between) or click Custom Filter.

2.

In the Custom AutoFilter dialog box, in the box on the right, enter a date or time, select a date or time from the list, or click the Calendar button to find and enter a date.

For example, to filter by a lower and upper date or time, select Between.

3.

In the Custom AutoFilter dialog box, in the box or boxes on the right, enter a date or time, select dates or times from the list, or click the Calendar button to find and enter a date.

For example, to filter by an earlier date of "3/1/2006" and a later date of "6/1/2006", enter 3/1/2006 and 6/1/2006. Or, to filter by an earlier time of "8:00 AM" and a later time of "12:00 PM", enter 8:00 AM and 12:00 PM.

Dynamic filter

NOTE

A dynamic filter is one where the criteria can change when you reapply the filter.

4.

Click one of the pre-defined date commands.

For example, to filter all dates by the current date, select Today, or by the following month, select Next Month.

5.

Click OK.

NOTES

The commands under the All Dates in the Period menu, such as January or Quarter 2, filter by the period no matter what the year. This can be useful, for example, to compare sales by a period across several years.

This Year and Year to Date are different in the way that future dates are handled. This Year can return dates in the future for the current year, whereas Year to Date only returns dates up to and including the current date.

2.

Optionally, filter by one more criteria.

How to add one more criteria

1.

Do one of the following:

 
2.

To filter the table column or selection so that both criteria must be true, select And. To filter the table column or selection so that either or both criteria can be true, select Or. In the second entry, select a comparison operator, and then in the box on the right, enter a date or time, select a date or time from the list, or click the Calendar button to find and enter a date.

To reapply a filter after you change the data, click a cell in the range or table, and then on the Data tab, in the Sort & Filter group, click Reapply.

NOTES

All date filters are based on the Gregorian calendar. Fiscal years and fiscal quarters always start in January of the calendar year. If you want to filter by days of the week, format the cells to show the day of the week. If you want to filter 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 filter command that is displayed would be Text Filters, not Date Filters. For more information, see Show dates as days of the week. For the list of dates at the bottom of the AutoFilter menu in a date filter, you can change the hierarchical grouping of dates to a nonhierarchical list of dates. For example, you can filter for just two-digit years by manually selecting them from a nonhierarchical list. 1. Click the Microsoft Office Button category. 2. In the Display options for this workbook section, select a workbook, and then clear the Group dates in the AutoFilter menu check box. , click Excel Options, and then click the Advanced

Top of Page

Filter for top or bottom numbers


1. Do one of the following:

Range of cells

1. 2.

Select a range of cells containing numeric data. On the Data tab, in the Sort & Filter group, click Filter.

Table

Make sure that the active cell is in a table column that contains numeric data. Click the arrow in the column header.

Point to Number Filters and then select Top 10. In the Top 10 AutoFilter dialog box, do the following. 0. 1. 2. In the box on the left, click Top or Bottom. In the box in the middle, enter a number. In the box on the right, do one of the following:

 

To filter by number, click Items. To filter by percentage, click Percent. To reapply a filter after you change the data, click a cell in the range or table, and then on the Data tab,

in the Sort & Filter group, click Reapply.

NOTE

Top and bottom values are based on the original range of cells or table column and not the filtered subset of

data.

Top of Page

Filter for above or below average numbers


1. Do one of the following:

Range of cells

1. 2.

Select a range of cells containing numeric data. On the Data tab, in the Sort & Filter group, click Filter.

Table

Make sure that the active cell is in a table column that contains numeric data. Click the arrow in the column header.

Point to Number Filters and then do one or more of the following:

 

To filter by numbers that are above the average, click Above Average. To filter by numbers that are below the average, click Below Average. To reapply a filter after you change the data, click a cell in the range or table, and then on the Data tab, in the Sort & Filter group, click Reapply.

NOTE

Above and below average numbers are based on the original range of cells or table column and not the

filtered subset of data.

Top of Page

Filter for blanks or nonblanks


1. Do one of the following:

Range of cells

1. 2.

Select a range of cells. On the Data tab, in the Sort & Filter group, click Filter.

Table

Make sure that the active cell is in a table column. Click the arrow in the column header.

Do one of the following:

To filter for nonblanks, in the AutoFilter menu at the top of the list of values, select (Select All), and then at the bottom of the list of values, clear (Blanks).

To filter for blanks, in the AutoFilter menu at the top of the list of values, clear (Select All), and then at the bottom of the list of values, select (Blanks).

NOTE

The (Blanks) check box is available only if the range of cells or table column contains at least one

blank cell.

To reapply a filter after you change the data, click a cell in the range or table, and then on the Data tab, in the Sort & Filter group, click Reapply.

Top of Page

Filter by cell color, font color, or icon set


If you have manually or conditionally formatted a range of cells, by cell color or font color, you can also filter by these colors. You can also filter by an icon set created through a conditional format.

1.

Do one of the following:

Range of cells

1. 2.

Select a range of cells containing formatted by cell color, font color, or an icon set. On the Data tab, in the Sort & Filter group, click Filter.

Table

Make sure that the table column contains data formatted by cell color, font color, or an icon set (No selection is required).

Click the arrow

in the column header.

Select Filter by Color, and then depending on the type of format, select Filter by Cell Color, Filter by Font Color, or Filter by Cell Icon. Depending on the type of format, select a color, font color, or cell icon. To reapply a filter after you change the data, click a cell in the range or table, and then on the Data tab, in the Sort & Filter group, click Reapply.

Top of Page

Filter by selection
You can quickly filter data with criteria that is equal to the contents of the active cell.

1.

In a range of cells or table column, right click a cell containing the value, color, font color, or icon you want to filter by.

2.

Click Filter, and then do one of the following:

   
3.

To filter by text, number, or date or time, click Filter by Selected Cell's Value. To filter by cell color, click Filter by Selected Cell's Color. To filter by font color, click Filter by Selected Cell's Font Color. To filter by icon, click Filter by Selected Cell's Icon. To reapply a filter after you change the data, click a cell in the range or table, and then on the Data tab, in the Sort & Filter group, click Reapply.

Top of Page

Clear a filter
You can clear a filter for a specific column or clear all filters.

Clear a filter for a column


To clear a filter for one column in a multicolumn range of cells or table, click the Filter button heading, and then click Clear Filter from <Column Name>. on the

Clear all filters in a worksheet and redisplay all rows


On the Data tab, in the Sort & Filter group, click Clear.

You might also like