Sub topic 11
Filter with Complex Criteria Using Advanced Filter
This chapter assumes you can apply an AutoFilter, read comparison operators such as >=, and select a range in a worksheet. AutoFilter handles simple conditions well. Advanced Filter covers cases AutoFilter cannot, such as several OR conditions across different columns, or copying the matching rows to another place.
How Advanced Filter works
Advanced Filter reads its conditions from a criteria range, which is a small block of cells on the worksheet. You build this block yourself. Excel then compares each row of your data against it.
You need three things:
- A list range: your data, including the header row.
- A criteria range: copies of the header names, with conditions beneath them.
- Optionally, a copy-to location, if you want the results kept apart from the original data.
Find the command on the Data tab, in the Sort & Filter group, under Advanced.
Build a criteria range
The header in the criteria range must match the data header exactly, including spelling and spaces. A mismatch is the most common reason an Advanced Filter returns nothing. Copy and paste the header cells to be safe.
The example below returns rows where Region is West and Amount is at least 500.
Region Amount
West >=500Conditions on the same row combine with AND. Conditions on separate rows combine with OR. To get rows where Region is West, or Region is East, put each on its own row:
Region
West
EastTo mix them, such as West with an amount of at least 500, or any East row, use two rows:
Region Amount
West >=500
EastThe empty Amount cell under East means no condition on Amount for that row.
Run the filter
- Place the criteria range on the sheet, with at least one blank row or column between it and the data. Putting it above the data is common, because the list can then grow downward.
- Click any cell inside your data.
- Choose Data > Advanced.
- Choose Filter the list, in-place to hide non-matching rows. Choose Copy to another location to write the matches elsewhere.
- Confirm that List range covers your data and header. Set Criteria range to the header cell and the condition cells together.
- If you chose to copy, set Copy to to the top-left cell of an empty area.
- Optionally, tick Unique records only to drop duplicate rows.
To restore the hidden rows after an in-place filter, choose Data > Clear.
Text and wildcard conditions
Text conditions have some quirks. Typing West in a criteria cell matches any value that starts with "West", such as "Western". For an exact match, type ="=West". You can also use wildcards: * matches any run of characters and ? matches a single character. For example, S* matches every value that starts with S.
When to use it
| Need | Better tool |
|---|---|
| Simple conditions on one or two columns | AutoFilter |
| Results that stay current as data changes | FILTER function |
| Complex AND/OR logic, or a one-time extract to another place | Advanced Filter |
Exercise
A criteria range has the headers Region and Amount. Under Region you type West on row 2 and East on row 3. Under Amount you type >=500 on row 2 only. Which rows does Advanced Filter return?
Show answer
It returns rows where Region is West and Amount is at least 500, plus every row where Region is East, whatever its amount. Row 2 combines its two conditions with AND. Row 3 has a single condition, and the two rows combine with OR.