Chapter 7: Automate Repetitive Database Tasks
6.2 Filter Data with AutoFilter
You can use Excel’s AutoFilter feature to quickly show only those data records that match the criteria you specify. For example, you could show only sales data records that pertain to sales transactions in an eastern sales territory in the month of September that deal with more than 100 units of product.
Quick Start
To filter data in a group of cells in an Excel worksheet, do the following:
1. Select a single cell (preferably a data column heading in the first row) within the group of cells that you want to sort.
2. In Excel 2007, click Home ➤(Editing) Sort & Filter ➤Filter. In Excel 2003, click Data ➤ Filter ➤AutoFilter.
3. Click one of the AutoFilter buttons (the buttons with the downward pointing arrows inside of the cells), and select one of the commands in the AutoFilter list. Only the data records matching the AutoFilter criteria are displayed.
How To
To filter data in a group of cells in an Excel worksheet, do the following:
1. Select a single cell (preferably a data column heading in the first row) within the group of cells that you want to filter.
2. In Excel 2007, click Home ➤(Editing) Sort & Filter ➤Filter. In Excel 2003, click Data ➤ Filter ➤AutoFilter.
When you click one of the AutoFilter buttons (a button showing the down arrow in each of the heading row’s cells), choose one of the commands in the AutoFilter list:
• Select Sort A to Z or Sort Smallest to Largest (in Excel 2007) or Sort Ascending (in Excel 2003) to sort the data records in ascending order according to the data values for that particular data field.
• Select Sort Z to A or Sort Largest to Smallest (in Excel 2007) or Sort Descending (in Excel 2003) to sort the data records in descending order according to the data values for that particular data field.
• Select Clear Filter From (in Excel 2007) or (All) (in Excel 2003) to remove AutoFilter cri- teria for that particular data field.
• Select Number Filters ➤Top 10 (for number-based data fields in Excel 2007) or (Top 10 . . .) (in Excel 2003) to show up to the top or bottom 500 items or a percentage of the top or bottom data values for that particular data field. In the Top 10 AutoFilter dialog box, in the Show area, in the left box, select Top or Bottom. In the middle box select a number from 1 to 500. In the right box select Items or Percent. Then click OK.
• Select Text Filters ➤Custom Filter or Number Filters ➤Custom Filter (in Excel 2007) or (Custom . . .) (in Excel 2003) to show data records that match specific criteria.
• Select one of the data values in the list to show only data records with matching data values.
• If applicable, select (Blanks) to show only data records that have a blank cell for that particular data field.
• If applicable, select (NonBlanks) to show only data records that have a data value for that particular data field.
• To sort by color, click Sort by Color (Excel 2007 only).
• To display data records by color, click Filter by Color (Excel 2007 only).
• To display data records that match one of a selected list of specific data values, select the check box next to each specific data value (Excel 2007 only).
C H A P T E R 6 ■ A N A LY Z E D ATA 141
■ Tip You can apply additional AutoFilter criteria to multiple data fields. For example, let’s pretend that you apply AutoFilter criteria to column B to show only data records with the data value North in column B. Of the records that are still showing, you could then apply an additional AutoFilter criteria to column E to show only data records with data values that are less than 100 in column E.
Each column that has AutoFilter criteria applied will display a blue downward pointing area in the AutoFilter button. To remove AutoFilter criteria for a single column, click the AutoFilter button, and then click Clear Filter From (in Excel 2007) or (All) (in Excel 2003). To remove AutoFilter criteria for all columns, click Home ➤ (Editing) Sort & Filter ➤Clear (in Excel 2007) or Data ➤Filter ➤AutoFilter (in Excel 2003).
If you select Text Filters ➤Custom Filter or Number Filters ➤Custom Filter (in Excel 2007) or (Custom . . .) (in Excel 2003), do the following:
1. In the top left list, select one of the following choices:
• Select Equals or Does Not Equal to specify data values that are equal to or not equal to the data value specified in the list to the right.
• Select Is Greater Than or Is Greater Than or Equal To to specify data values that are greater than or greater than or equal to the data value specified in the list to the right.
• Select Is Less Than or Is Less Than or Equal To to specify data values that are less than or less than or equal to the data value specified in the list to the right.
• Select Begins With or Does Not Begin With to specify data values that begin with or do not begin with the data value specified in the list to the right.
• Select End With or Does Not End With to specify data values that end with or do not end with the data value specified in the list to the right.
• Select Contains or Does Not Contain to specify data values that contain or do not contain the data value specified in the list to the right.
2. In the top right list, type the data value to which you want to evaluate the condition in the top left list.
■ Note You can use the question mark (?) character to represent any single character. You can use the asterisk (*) character to represent any series of characters. For example, you can use Southe??or Southe*
to match the data values Southend or Southern.
3. To apply an additional criteria, click the Add option or the Or option to apply an inclu- sive or exclusive filter criteria, respectively. Then repeat steps 1 and 2 for the bottom left list and bottom right list, respectively. Then click OK.
Try It
In this exercise, you will practice using the AutoFilter feature on a portion of United States census data to show data records matching specific criteria.
If the Excel workbook file is not open from the previous exercise, open it:
1. Start Excel.
2. Click Office Button ➤Open (in Excel 2007) or File ➤Open (in Excel 2003), browse to and select the ExcelDB_Ch06_01-05.xls file, and click Open.
Show data records only from counties in the state of Florida where the population and housing units both exceed 100,000:
1. On the Counties worksheet tab, click any single cell in row 1 on the Counties worksheet tab in columns A through G.
2. In Excel 2007, click Home ➤(Editing) Sort & Filter ➤Filter. In Excel 2003, click Data ➤ Filter ➤AutoFilter.
3. Click the AutoFilter button in cell A1, and then show data records only from Florida counties. In Excel 2007, clear the (Select All) check box, select the FL check box, and then click OK. In Excel 2003, select FL.
4. Click the AutoFilter button in cell D1, and then in Excel 2007, click Number Filters ➤ Custom Filter. In Excel 2003, select (Custom . . .).
5. In the Custom AutoFilter dialog box, in the top left list, select Is Greater Than.
6. In the right box, type 100000, and then click OK. Only data records from Florida counties with populations greater than 100,000 are shown.
7. Click the AutoFilter button in cell E1, and then in Excel 2007, click Number Filters ➤ Custom Filter. In Excel 2003, select (Custom . . .).
8. In the Custom AutoFilter dialog box, in the top left list, select Is Greater Than.
9. In the right box, type 100000, and then click OK. Only data records from Florida coun- ties with populations greater than 100,000 and housing units greater than 100,000 are shown.
10. Remove the AutoFilter criteria. In Excel 2007, click Home ➤(Editing) Sort & Filter ➤ Filter or Home ➤(Editing) Sort & Filter ➤Clear. In Excel 2003, click Data ➤Filter ➤ AutoFilter.