Filter Data with Advanced Criteria

Một phần của tài liệu Sử dụng Excel thiết lập cơ sở dữ liệu (Trang 162 - 166)

Chapter 7: Automate Repetitive Database Tasks

6.3 Filter Data with Advanced Criteria

Excel allows you to filter data with more advanced criteria then you can specify using the AutoFilter cell buttons or the AutoFilter dialog box. For example, with the AutoFilter feature, 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, while with advanced criteria, you could show only sales data records that pertain to sales transactions in

C H A P T E R 6 ■ A N A LY Z E D ATA 143

eastern or western sales territories in the months of September or October that deal with between 100 and 500 units of product.

Quick Start

To apply advanced filter criteria to a group of cells, do the following:

1. Insert at least three blank rows above the group of cells that you want to filter. There must be at least one blank row between the advanced filter criteria and the group of cells that you want to filter, and both the advanced filter criteria’s first row and the cell group’s first row must contain data field labels.

2. Type the advanced filter criteria in the blank rows.

3. In Excel 2007, click Data ➤(Sort & Filter) ➤Advanced. In Excel 2003, click Data ➤Filter

➤Advanced Filter.

4. Complete the Advanced Filter dialog box, and click OK.

How To

To apply advanced filter criteria to a group of cells, do the following:

1. Insert at least three blank rows above the group of cells that you want to filter. You will use these blank rows to specify your advanced filter criteria. There must be at least one blank row between the advanced filter criteria and the group of cells that you want to filter, and both the advanced filter criteria’s first row and the cell group’s first row must contain data field labels.

2. Type the advanced filter criteria in the blank rows (see the examples in Tables 6-1 through 6-4). Place inclusive filter criteria (“and”) on the same row. Place exclusive filter criteria (“or”) on separate rows.

3. In Excel 2007, click Data ➤(Sort & Filter) ➤Advanced. In Excel 2003, click Data ➤Filter

➤Advanced Filter.

In the Advanced Filter dialog box, do the following:

1. In the Action area, select the Filter the List, In-Place option to display only data records that match the specified criteria. Select the Copy to Another Location option to copy to another location the data records that match the specified criteria.

2. In the List Range box, type or select the group of cells that you want to filter.

3. In the Criteria Range box, type or select the group of cells that contain the advanced filter criteria.

4. If you select the Copy to Another Location option, in the Copy To box, type or select the cell location to which you want to start copying the data records that match the specified criteria.

When you are done, click OK to apply the specified advanced filter criteria to the target cell group.

Note For information on the Unique Records Only check box, see section “6.4: Filter for Unique Data.”

Table 6-1 shows some example data to which advanced filter criteria are applied in Table 6-2.

Table 6-1.Example Data Records to Apply Advanced Filter Criteria

Sales Date Product Name Units Sold

1-Jan Widgets 50

1-Jan Gaskets 75

1-Jan Gears 150

2-Jan Widgets 125

2-Jan Gaskets 100

2-Jan Gears 250

3-Jan Widgets 150

3-Jan Gaskets 125

3-Jan Gears 325

See Table 6-2 for an example of showing only data records that match these advanced filter criteria: sales dates after January 2, product names beginning with the letter G, and units sold in excess of 100.

Table 6-2.Advanced Filter Criteria for Data Records

Sales Date Product Name Units Sold

>1-Jan =“G*” >100

Sales Date Product Name Units Sold

2-Jan Gears 250

3-Jan Gaskets 125

3-Jan Gears 325

Table 6-3 shows an example of data records that match these advanced filter criteria: sales dates on January 1 or January 3, and number of units sold less than 150.

Table 6-3.Advanced Filter Criteria and Results for Data Records Sales Date Units Sold

1-Jan <150

3-Jan <150

Sales Date Product Name Units Sold

1-Jan Widgets 50

1-Jan Gaskets 75

3-Jan Gaskets 125

C H A P T E R 6 ■ A N A LY Z E D ATA 145

Table 6-4 shows an example of showing only data records that match these advanced fil- ter criteria: sales dates of January 2, units sold of less than 150, and product names ending in the letters ets.

Table 6-4.Advanced Filter Criteria and Results for Data Records

Sales Date Product Name Units Sold

2-Jan <150

*ets

Sales Date Product Name Units Sold

1-Jan Widgets 50

1-Jan Gaskets 75

2-Jan Widgets 125

2-Jan Gaskets 100

3-Jan Widgets 150

3-Jan Gaskets 125

Tip To remove advanced filter criteria, clear the Home ➤(Editing) Sort & Filter ➤Clear command (in Excel 2007) or click Data ➤Filter ➤Show All (in Excel 2003).

Try It

In this exercise, you will practice using advanced filter criteria on a portion of United States census data to show matching data records.

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.

First, display data records for counties in the state of Florida with the words North or South in the county name and a land area of more than 500:

1. Insert four blank rows between the top of the Counties worksheet and the data records.

2. Type the advanced filter criteria shown in Table 6-5 in cells A1 through C3.

Table 6-5.Advanced Filter Criteria for the Counties Worksheet

State County_Name Land_Area

FL North >500

FL South >500

3. Click cell A5, and then in Excel 2007, click Data ➤(Sort & Filter) ➤Advanced. In Excel 2003, click Data ➤Filter ➤Advanced Filter.

4. In the Advanced Filter dialog box, with the List Range box showing the cell reference of cells A5 through G5409, click the Criteria Range list, select cells A1 through C3, and click OK. Three matching records are displayed.

5. In Excel 2007, click Home ➤(Editing) Sort & Filter ➤Clear. In Excel 2003, click Data ➤ Filter ➤Show All.

Now, display data records for counties in the states of California or Colorado with popula- tions between 200,000 and 300,000 and housing units of more than 100,000:

1. With the four rows between the top of the worksheet and the data records, replace the contents of cells A1 through C3 with the advanced filter criteria shown in Table 6-6 in cells A1 through D3.

Table 6-6.More Advanced Filter Criteria for the Counties Worksheet

State Population Population Housing_Units

CA >200000 <300000 >100000

CO >200000 <300000 >100000

2. Click cell A5, and in Excel 2007, click Data ➤(Sort & Filter) ➤Advanced. In Excel 2003, click Data ➤Filter ➤Advanced Filter.

3. In the Advanced Filter dialog box, with the List Range box showing the cell reference of cells A5 through G5409, clear the contents of the Criteria Range list, select cells A1 through D3, and click OK. Three matching records are displayed.

4. Remove the advanced filter criteria from the worksheet before moving on to the next section. In Excel 2007, click Home ➤(Editing) Sort & Filter ➤Clear. In Excel 2003, click Data ➤Filter ➤Show All. Make sure also to delete the first four rows of the worksheet containing the advanced filter criteria.

Một phần của tài liệu Sử dụng Excel thiết lập cơ sở dữ liệu (Trang 162 - 166)

Tải bản đầy đủ (PDF)

(245 trang)