Ozgrid, Experts in Microsoft Excel Spreadsheets



Excel Training Level 3 Lesson 3-Excel 97-2003



Download the associated  Workbook for this lesson

In this lesson, we will have a good look at one of Excel's arguably most useful features and that is the Advanced Filter. Before we do however, we would like to outline what we believe is very important in regards to tables and lists.

Tables and Lists Guidelines

In the context we are discussing here, a Table is no more than a List with more than one Column of data. A List is often referred to in the context of a Table as well. The 'good practice' that applies to setting up a List will aid us greatly when we need to filter down our data via the use of the AutoFilter and AdvancedFilter.

When we extract data via the use of Lookup functions or Database functions we can be a little less stringent in how we set up our Table or List. This is because we can always compensate with the aid of a function and probably still get our result. However, having said this we should always set up our List or Table as well as possible. When we use Excels built-in features they will and do assume a lot about the layout and setting up of your data. They do have a degree of flexibility but more often than not you will find it easier to follow the guidelines for setting up your Table or List.

Let's look at what we believe to be the most important aspects of setting up a Table or List. The term "Filters" will be in reference to AutoFilters and AdvancedFilters.

  1. Headings. This is a must! They should always be in the row directly above your data. Never have a blank row between your data and the headings. Make them distinct in some way eg; bold them.

  2. Leave at least three blank rows above your headings. These can be used for formulas, critical data etc. You can hide the rows if you wish.

  3. If you have more than one List, use a different worksheet for each List. This way you can use Filters on any List without it interfering with another List.

  4. Organise your data so that related data is close. This will make reading from a Filtered list much easier.

  5. Filters will only hide Rows not Columns.

  6. If you have data that needs to be seen all the time don't place it to the left or right of your data as it will be hidden once you apply Filters.

  7. If you do have more than one List or Table on the same Worksheet leave at least one blank column between your List and Table. This will aid Excel in recognising them as separate.

  8. Avoid blank cells within your data.

  9. Sort your List or Data. This in not so much for Filters, but for the person reading the data.

If we follow these guidelines as close as possible, using Filters will be a relatively easy task.  

Advanced Filters

As you are now at the Advanced Level of Excel, you should be fully aware of Excel's AutoFilter feature.  While in most cases the AutoFilter is quite sufficient for most tables or lists, there are times when you need to extract data that cannot be extracted via Excel's AutoFilter.  Probably the three biggest differences between the Advanced Filter and Excel's AutoFilter are:

  1. Advanced Filter will allow us to nominate where we would like our filtered data to be placed.  The choices are:  Filter the list, in place or Copy to another location.

  2. Advanced Filter has a built-in function that will allow us to filter by unique records.

  3. Advanced Filter allows us to use a formula as our criteria.

Before we go into detail on these, there are a couple of rules that must be adhered to when using the Advanced Filter in certain ways. 

  1. In relation to Point 1 - The list must be filtered to a nominated range on the same Worksheet as the list or table resides.  This means simply if our list or table is on Sheet 1, Excel will not allow us to nominate the Copy to another location option and copy to another Worksheet, we have to copy to the same Worksheet that our list or table resides on. If you do wish to copy to another Worksheet simply opt  to Copy to another location on the same Worksheet, then cut and paste the results to another Worksheet. 

  2. In relation to Point 3 - When we use a formula as our criteria, the formula itself must evaluate to either True or False.  We will be using formulas later, and you will see what I mean when I show you the example.

Let's start off with something relatively simple, so download the attached workbook and and open the file ExcLev3L02a.xls

In the table on the AdvancedFilters worksheet, the heading Names is in cell A6.  The reason we have started in this cell is because it is good practice to always leave at least three spare rows above your data.  We usually opt for more than this as we have 65536 rows in total. This is so we can use them for setting a Criteria for an Advanced Filter. When you set a Criteria you refer to it using the Criteria range box. Your criteria range should include the column headings of your List or Table. So we simply copy our column headings to the top blank row. It is below these headings that we put our criteria.

An important point to note here is that column heading names should be unique.  Again, this will become apparent once we start using a criteria for our example.

When you first activate the Advanced filter, it will (by default) include all surrounding cells that have data in them. This is known as the Current Region.  For this to happen though you should select any single cell within your table before activating the Advanced filter.

What we would like you to do now is copy the headings and paste to cells A1:C1. Now select the range A6:C27 and name this MyRange. Then follow the steps below.

  1. Type John in cell A2 and Dave in cell A3.

  2. Select any cell within your Table and go to Data>Filter>Advanced Filter.

  3. Select Filter the list in place.

  4. Make sure your List range is correct. Advanced Filter will automatically pick up your list range as you have clicked in a cell inside your list and your list is set up correctly.  The List range should be A6:C27, although you could type in MyRange if you prefer.

  5. Put A1:A3 in our Criteria range box

  6. Click OK

Our Table should now only display the information for John and Dave.  All other rows should be hidden in the same manner as the AutoFilter hides rows. In other words all visible rows will have blue row numbers. To get or data back to how it was go to Data>Filter>Show All, do this now.

To add more names we could insert some more rows above our data and use these to add the extra names. However we believe it is better to have the extra rows there to begin with, and as we have said previously, leave at least three rows above your data and hide them. 

Now all your data is visible again follow these steps.

  1. Select any cell within your Table and go to Data>Filter>Advanced Filter.

  2. Make sure our List range is correct. It should be A6:C27 (MyRange)

  3. Put A1:A3 in our Criteria range box

  4. Check the Copy to another location option.

  5. Click the collapse dialog box to the right of the Copy to box.

  6. Select cell F6 then click the expand dialog box.

  7. Click OK

This time instead of the names that do not meet the criteria being hidden they are simply not included in the copied table. 

We could also extend our criteria to not only show John and Dave's information, but to show only John and Dave IF they are aged between 25 and 52. To do this we would put: >24 in the cell directly below our copied heading Age and <53 in the cell below this. Now apply the Advanced Filter and include the new criteria in the Criteria box ie; A1:C3, although our new criteria for the age is in cells C1:C3. It wont matter that there is no criteria in cells B1:B3 as blank cells are ignored.

Now return the Worksheet to how it was originally. In other words have the table only, but retain the copied headings in row 1.

We can also use formulas as our criteria when using Advanced Filter, which can make our filtering capabilities even more complex. However any formula we use:

  1. Must evaluate to either TRUE or FALSE.

  2. The formula we use, must use a relative cell reference to the first data cell in the column we want to filter.

  3. The range within the formula itself must be an absolute reference.

If we do not apply these three rules the Advanced Filter will not work as expected.

So let's say we wanted to find the information on the person who has the third largest pay rate. To do this we need to place the formula: =B7=LARGE($B$7:$B$27,3) in cell B2. Where B7 is our first Pay Rate and $B$7:$B$27 is the entire range below Pay Rate.

When we use the Advanced Filter this time we must not have our column heading Pay Rate in cell B1. We would still refer our Criteria range in the Advanced Filter dialog to: $B$1:$B$2 but we cannot have a column heading in B1 that is the same as  one in the Table. In other words we use the formula cell and a blank cell above it, or type any text just as long as it is not the same as a column heading from our Table. For this example we will leave it blank, so delete the words Pay Rate from cell B1.  Notice also that we are using $B$1:$B$2 and not $A$1:$C$2.  This is because we can only include cells which do have a criteria set.

Now follow these steps:

  1. Select any cell within your Table and go to Data>Filter>Advanced Filter.

  2. Make sure our List range is correct. It should be A6:C27 (MyRange)

  3. Put B1:B2 in our Criteria range box

  4. Check the Copy to another location option.

  5. Click the collapse dialog box to the right of the Copy to box.

  6. Select cell F6 then click expand dialog box

  7. Click OK

You should now have Jim - $21.00 - 40 as your result.

The other very handy feature of the Advanced Filter is that we can use it to create a List of Unique records only. To do this we simply need to check the Unique records only box and leave the Criteria range box blank. When we use this option it is usually using a single column as our List range. Try this to see what we mean. But first remove all data leaving only your table.

  1. Select any cell within your Table and go to Data>Filter>Advanced Filter.

  2. Make your  List range  C6:C27 

  3. Ensure the Criteria range box is blank.

  4. Check the Filter the list, in place option.

  5. Check the Unique records only option.

  6. Click OK

You should now have a filtered list which only shows one occurrence of each age!

We could also use this same method to show only one occurrence of duplicated row data, try this:

  1. Copy A12:C12 and paste over the top of A11:C11

  2. Select any cell within your Table and go to Data>Filter>Advanced Filter.

  3. Make your  List range  A6:C27 

  4. Ensure the Criteria range box is blank.

  5. Check the Filter the list, in place option.

  6. Check the Unique records only option.

  7. Click OK

This time, row 12 will be hidden as it is a duplicate of row 11.

We have included a Workbook example of Advanced Filters (ExcLev3L02b.xls) to give you an idea on how they can be used. There is also some good information in the Excel help under: Filter a list using advanced criteria that is worth reading. As with the use of most formulas in Excel, it can take some trial and error before we get the result we want. However, making mistakes is a great way to learn!!!