Sunteți pe pagina 1din 5

260 Part II: Using Functions in Your Formulas

You can put the criteria range anywhere in the worksheet or even in a different worksheet.
However, you should avoid putting the criteria range in rows that are occupied by the worksheet
database or table. Because Excel may hide some of these rows when filtering, you may find that
your criteria range is no longer visible after filtering. Therefore, you should generally place the
criteria range above or below the table.
Figure 9-16 shows a criteria range in A1:B2, above the worksheet database that it uses. Notice
that the criteria range does not include all the field names from the table. You can include only
the field names for fields that you use in the selection criteria.

Figure 9-16: A criteria range for advanced filtering.

In this example, the criteria range has only one row of criteria. The fields in each row of the crite-
ria range (except for the Header row) are joined with an AND operator. Therefore, after applying
the advanced filter, the worksheet database shows only the rows in which the Bedrooms field is 3
and the Pool field is TRUE. In other words, it shows only the listings for three-bedroom homes
with a pool.
You may find specifying criteria in the criteria range a bit tricky. I discuss this topic in detail later
in this chapter in the section, “Specifying Advanced Filter Criteria.”

Applying an advanced filter


To perform the advanced filtering:

1. Ensure that you’ve set up a criteria range.


2. Choose Data➜Sort & Filter➜Advanced.
Excel displays the Advanced Filter dialog box, as shown in Figure 9-17.
3. Excel guesses your database range if the active cell is within or adjacent to a block of
data, but you can change it if necessary.
4. Specify the criteria range.
If you happen to have a named range with the name Criteria, Excel will insert that range
in the Criteria Range field — you can also change this range if you like.

14_475362-ch09.indd 260 4/14/10 10:09 PM


Chapter 9: Tables and Worksheet Databases 261

Figure 9-17: The Advanced Filter dialog box.

5. To filter the database in place (that is, to hide rows that don’t qualify), select the option
labeled Filter the List, In-Place.
If you select Copy to Another Location, you need to specify a range in the Copy To field.
6. Click OK, and Excel filters the table by the criteria that you specify.

Figure 9-18 shows the worksheet database after applying the advanced filter that displays three-
bedroom homes with a pool.

Figure 9-18: The result of applying an advanced filter.

When you select the Copy to Another Location option, you can specify which columns
to include in the copy. Before displaying the Advanced Filter dialog box, copy the
desired field labels to the first row of the area where you plan to paste the filtered
rows. In the Advanced Filter dialog box, specify a reference to the copied column labels
in the Copy To field. The copied rows then include only the columns for which you cop-
ied the labels.

14_475362-ch09.indd 261 4/14/10 10:09 PM


262 Part II: Using Functions in Your Formulas

Clearing an advanced filter


When you apply an advanced filter, Excel hides all rows that don’t meet the criteria you specified.
To clear the advanced filter and display all rows, choose Data➜Sort & Filter➜Clear.

Specifying Advanced Filter Criteria


The key to using advanced filtering is knowing how to set up the criteria range — which is the
focus of the sections that follow. You have a great deal of flexibility, but some of the options are
not exactly intuitive. Here you’ll find plenty of examples to help you understand how to create a
criteria range that extracts the information you need.

The use of a separate criteria range for advanced filtering originated with the original
version of Lotus 1-2-3, more than 20 years ago. Excel adapted this method, and it has
never been changed, despite the fact that specifying advanced filtering criteria remains
one of the most confusing aspects of Excel. Fortunately, however, Excel’s standard fil-
tering is sufficient for most needs.

Specifying a single criterion


The examples in this section use a single-selection criterion. In other words, the contents of a sin-
gle field determine the record selection.

You also can use standard filtering to perform this type of filtering.

To select only the records that contain a specific value in a specific field, enter the field name in
the first row of the criteria range and the value to match in the second row. Figure 9-19, for
example, shows the criteria range (A1:A2) that selects records containing the value 4 in the
Bedrooms field.

Figure 9-19: The criteria range (A1:A2) selects records that describe homes with four bedrooms.

14_475362-ch09.indd 262 4/14/10 10:09 PM


Chapter 9: Tables and Worksheet Databases 263

Note that the criteria range does not need to include all the fields from the database. If you work
with different sets of criteria, you may find it more convenient to list all the field names in the
first row of your criteria range.

Using comparison operators


You can use comparison operators to refine your record selection. For example, you can select
records based on any of the following:

h Homes that have at least four bedrooms


h Homes with a square footage less than 2,000
h Homes with a table price of no more than $200,000

To select the records that describe homes that have at least four bedrooms, type Bedrooms in
cell A1 and then type >=4 in cell A2 of the criterion range.
Table 9-2 lists the comparison operators that you can use with text or value criteria. If you don’t
use a comparison operator, Excel assumes the equal sign operator (=).

Table 9-2: Comparison Operators


Operator Comparison Type
= Equal to
> Greater than
>= Greater than or equal to
< Less than
<= Less than or equal to
<> Not equal to

Using wildcard characters


Criteria that use text also can make use of two wildcard characters: An asterisk (*) matches any
number of characters; a question mark (?) matches any single character.
Table 9-3 shows examples of criteria that use text. Some of these are a bit counter-intuitive. For
example, to select records that match a single character, you must enter the criterion as a for-
mula (refer to the last entry in the table).

The text comparisons are not case sensitive. For example, se* matches Seligman, seller,
and SEC.

14_475362-ch09.indd 263 4/14/10 10:09 PM


264 Part II: Using Functions in Your Formulas

Table 9-3: Examples of Text Criteria


Criteria Selects
=“=January” Records that contain the text January (and nothing else). You enter this exactly as shown:
as a formula, with an initial equal sign. Alternatively, you can use a leading apostrophe and
omit the quotes:
‘=January
January Records that begin with the text January.
C Records that contain text that begins with the letter C.
<>C* Records that contain any text, except text that begins with the letter C.
>=L Records that contain text that begins with the letters L through Z.
*County* Records that contain text that includes the word county.
Sm* Records that contain text that begins with the letters SM.
s*s Records that contain text that begins with S and has a subsequent occurrence of the letter S.
s?s Records that contain text that begins with S and has another S as its third character. Note
that this does not select only three-character words.
=”=s*s” Records that contain text that begins and ends with S. You enter this exactly as shown: as
a formula, with an initial equal sign. Alternatively, you can use a leading apostrophe and
omit the quotes:
‘=s*s
<>*c Records that contain text that does not end with the letter C.
=???? Records that contain exactly four letters.
<>????? All records that don’t contain exactly five letters.
<>*c* Records that do not contain the letter C.
~? Records that contain a single question mark character. (The tilde character overrides the
wildcard question mark character.)
= Records that contain a blank.
<> Records that contain any nonblank entry.
=”=c” Records that contain the single character C. You enter this exactly as shown: as a formula, with
an initial equal sign. Alternatively, you can use a leading apostrophe and omit the quotes:
‘=c

Specifying multiple criteria


Often, you may want to select records based on criteria that use more than one field or multiple
values within a single field. These selection criteria involve logical OR or AND comparisons.
Following are a few examples of the types of multiple criteria that you can apply to the real
estate database:

h A list price less than $250,000, and square footage of at least 2,000
h A single-family home with a pool
h At least four bedrooms, at least three bathrooms, and square footage less than 3,000

14_475362-ch09.indd 264 4/14/10 10:09 PM

S-ar putea să vă placă și