Download the associated Workbook for this lesson
In this lesson we will look at AutoFilters, AdvancedFilters and Range names. AutoFilters and AdvancedFilters will refer most often to a range of data set up in a table or list, while Range names can refer to any type of data. We will start by looking at how a table or list should be set up to take full advantage of AutoFilters and AdvancedFilters. The ability for these two features to operate to their full capabilities can often hinge on the data they are being used on.
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 I 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.
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.
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.
If you have more than one list, use another Worksheet for each list. This way you can use Filters on any list without it interfering with another list.
Organise your data so that related data is close. This will make reading from a Filtered list much easier.
Filters will only hide rows not columns.
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.
If you do have more than one list or table on the same Worksheet leave at least one blank column between your lists and tables. This will aid Excel in recognising them as separate.
Avoid blank cells within your data.
Sort your list or Data. This is 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.
The first type of Filter we will look at is the AutoFilter.
Excels AutoFilter is one Excels most useful features as it allows us to quickly and easily view data from within a table or list by hiding data we do not want to view. It does this by hiding rows that are within our data. One thing to keep in mind about the fact that it hides rows is that all 256 columns within the row will be hidden. It not possible to hide only a specified amount of columns. So hiding a row means the entire row!
To apply AutoFilters to your table or list click within any single cell of your data and go to Data>Filter>Auto Filter. Excel will detect your data by using what is known as the Current Region of the selected cell. So, as long as the table or list is set up correctly the AutoFilters will be applied to all headings. If not, you can select your headings and then go to Data>Filter>Auto Filter. You will see the Filters as small grey boxes with arrows on them. Click on anyone of them and you will see:
(All)
(Top Ten....)
(Custom....)
< A list of your data for that column>
The first three will always be the same and have the same meaning. Let's look at each in turn.
No big secrets here! This will simply show all your data in the column chosen if your data is being filtered down. There is also a Show All option under Data>Filter if the AutoFilters are hiding any rows. However, selecting Show All will unhide filtered rows for the entire Worksheet and not just the selected column.
While the (All) option is always available it will have no effect on unfiltered data. You can tell if a list or table is currently filtered by the arrow on the grey box (it will be blue) as will the visible row numbers.
This option only applies to numeric entries. So if the column you opt to filter contains no numeric entries, selecting it will have no effect. When you select this option you will see the Top Ten AutoFilter dialog box. Although the name says Top 10 we can change this to be the top or bottom of any number. It can also apply to a percentage. We simply set the first box to Top or Bottom and then spin (or type) up or down to the number we want. Be aware though the number must be between 1 and 500. If you select a number between 1 and 500 and it is not possible to achieve the result, Excel will still accept it and make your data appeared filtered (blue arrow and row numbers) even though it's not. In the final box you choose either Item or Percent.
A good example of this would be a list of consecutive numbers between 1 and 100. If we chose Top-50-Item we would see the numbers 51 to 100 and all other rows would be hidden. The exact same would apply if we chose Top-50-Percent. If we then applied Bottom-10-Item or Bottom-10-Percent we would see the numbers 1 to 10. In other words even though our list is only showing 51-100 the criteria is applied to all rows whether they are filtered or not. The same, however, does not apply if another column within your data is currently filtered. In this case, using the Top Ten would apply only to the currently visible rows.
When you select Custom from your filter options, you will see the Custom AutoFilter Dialog and the heading will be Show Rows Where: with the name of your chosen column heading directly below it. Below this there are four boxes.
Starting from the top left box - to the right of this you will see a drop down arrow. Click the arrow to select the settings for your criteria, eg; equals, does not equal etc. These options are always the same regardless of the type of data your table or list contains. Once you have selected the setting for your criteria, you would then move to the box immediately to the right. This is where you select the actual criteria that your setting will be applied to. If you click the drop arrow in this box, you will see a list of all unique items that are within the selected column. So for instance if you selected the Custom Filter option from a column that contains a list of data, let's say the 12 months of the year, and selected the setting greater than and the criteria April, and clicked OK, then you will see all the months that are greater than April. The reason we have used this example is to again stress the importance of using real dates in your cells and formatting them accordingly. In other words, if you simply had text dates, or text month names in your cells, and custom filtered as described above, Excel would hide only the row containing the word April. In other words, you would not get the result you expected.
You will probably also have noticed that you can use a question mark (?) to represent any single character and the asterisk (*) to represent any series of characters. An example of using this might be if you had a list of people's names and you only want to view all the names containing the letter g. To do this you would choose equals from the setting area and in the criteria box you would type *g* and select OK. You would be presented with a list of names that contain the letter g within them. You should note that the criteria you set is not case sensitive.
If you have a list which actually contains either one or both of these wildcard characters, and you wish to filter your list to display them only, you need to first type ~ (Tilde) followed by the wildcard character.
You will also have noticed that there are two option buttons on the Custom AutoFilter Dialog. These are And and Or. Using the same example as above (names) we could select begins with, G, select the or option and in the two boxes below select begins with and L. This will produce a list of names beginning with either G or L. If we chose begins with and G, then selected the and option and selected does not contain and n, we would get a list of all names beginning with G and not containing the letter n.
The terms in the Criteria Settings Box that contain the words greater or less will apply to numeric data only. All other settings apply to both text and numeric data.
This heading is in reference to all the items that you have in your currently selected column. The list will always be in ascending order, ie; A - Z, 1 - 100 regardless of how your data is sorted. You will only see one instance of each item regardless of how many times it appears within your list. In other words, you could have the name John in your list 20 times, but you will only see it appear in this list once. If however, you selected John from your list using a filter, you would see all 20 rows containing John and all other rows between hidden. In other words, selecting an entry from this list is exactly the same as using the Custom option with the setting equals to whatever.
Compound filtering in this context refers to filtering a table by more than one column. Doing this enables us to filter down a table by many different criteria. As mentioned before, when you apply a second criteria to a column that is already filtered, the first criteria will be removed. This is as opposed to applying a second criteria to your table in another column.
By doing this, we are telling Excel that we only want to filter down all visible rows (or rows that have not been hidden by an AutoFilter). An example of this could be a table with 10 columns and "X" amount of rows, with the first column being headed Names and the fourth column being headed Age. We could apply a filter criteria to the Names column to show only John, and then apply a filter to the Age column to show only ages greater than 20. Doing this our table would end up displaying only the information relating to people with the name John who are older than 20.
At times you may notice at the very bottom of your list displayed by the filter, the words (Blanks) and (NonBlanks). It can be a bit confusing as to why sometimes you may have these options, when other times you may not, even though you have a blank cells. Probably the best way to describe this is with a simple example. Let's use the same examples used above in Compound Filtering.
You may have blank cells within this table that are randomly distributed throughout. So long as you do not have 10 blank cells, all on the same row (the number 10 because we have 10 columns), you will have the options of Blank and NonBlanks if you select a column that contains blank cells. If however, you do have 10 blank cells, all on the same row, you will not have these options. In fact, Excel will, by default, assume that this is the end of your table. Again, this highlights the importance of avoiding blank cells if at all possible.
We can get by this by using a bit of trickery. There are a few ways in which this can be done.
Method 1
Probably the simplest method is to simply highlight your entire table, blank cells included, go to Edit>Replace, leave the Find What box blank and type any character you wish to use to represent your blank cells in the Replace With box.
Just be sure, use a character that is not in any way the same as any of your other data. The reason being that should you wish to remove these afterwards you want to be sure that you can use the Edit>Replace, type your character in the Find What box and leave the Replace With box blank. In other words, don't go using an alphabetic letter as you may end up inadvertently removing all those letters from your table.
Method 2
Create a dummy heading to the immediate left or right of your table, place any number or character in the first cell below the heading and use your fill handle to copy this to the last row of your data. Then apply the AutoFilter to include this dummy column. This will trick Excel into thinking that it is part of your table.
Method 3
Find your 10 consecutive blank cells on the same row, place any text or number in any one of the blank cells, apply your AutoFilter to the table, then remove the text or number you just typed in the blank cell. This again will trick Excel into thinking the cell that you typed your text or number in is still valid and exists within your table.
The Advanced Filter is used when you need to either filter your data down in a way that AutoFilter cannot and/or you want the result of your filtered data to be copied to another area on the Worksheet. The Advanced Filter dialog can be found by going to Data>Filter>Advanced filter.
You will see the option to either Filter the list, in place or Copy to another location. If you opt to Filter the list, in place, your table or list (list range) will be filtered in the same way as AutoFilter would do so. In other words it will hide all rows that do not meet the criteria as specified in the Criteria range: If you opt to Copy to another location your list range that meets the criteria as specified in the Criteria range will be copied to another location on the same Worksheet. The Copy to another location option does not allow you to copy your results to another Worksheet! If you do wish to do this simply opt to Copy to another location on the same Worksheet, then cut and paste the results to another Worksheet.
You may remember that point 2 in Guidelines for creating a table or list was:
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.
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.
Using the list of names example, we would have a copy of our heading Names in, say cell A1.
You could type John in cell A2 and Dave in cell A3.
Select any cell within your table and go to Data>Filter>Advanced Filter.
Select Filter the list in place.
Make sure your list range is correct.
Put A1:A3 in your Criteria range box
Click OK
Our table would then only display the information for John and Dave. To add more names we would 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.
We could, of course, do exactly the same and use the Copy to another location option, the only thing we would need to do is place a cell reference in the Copy to: box to start our new table in.
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 older than age 24. To do this we would put: >24 in the cell directly below our copied heading Age and >24 again in the cell below this. Then apply the Advanced Filter and include the new criteria in the Criteria box ie; A1:D3, where our new criteria for the age is in cells D1:D3. It does not matter that there is no criteria in cells B1:C3 as blank cells would be ignored.
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:
must evaluate to either TRUE or FALSE.
The formula we use, must use a relative cell reference to the first data cell in column we want to filter.
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 have the column heading Pay Rate in cell B6 and we wanted to find the information on the person who has the third largest pay rate. To do this we could use the formula: =B7=LARGE($B$7:$B$27,3) place it 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. In other words we use the formula cell and a blank cell above it. We can place data in cell B1 but it cannot be a column heading from our table.
We have included a Workbook example of Advanced Filters 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. But as we have said before "making mistakes is a great way to learn".
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 record only box and leave the Criteria range box blank. When we use this option though can only use include a single column list range.
It is also possible to create a list of Unique record only that also meet a criteria we have set. To do this we simply refer the Criteria range to a range that contains a criteria.
In Excel it is always good practice to name ranges, formulas and constants with meaningful names. Before we do so though, it may pay to have a quick refresher on some rules that must be adhered to when naming any of the above.
See below from the Excel Help
Guidelines for naming cells, formulas, and constants in Microsoft Excel
What characters are allowed? The first character of a name must be a letter or an underscore character. Remaining characters in the name can be letters, numbers, periods, and underscore characters.
Can names be cell references? Names cannot be the same as a cell reference, such as Z$100 or R1C1.
Can more than one word be used? Yes, but spaces are not allowed. Underscore characters and periods may be used as word separators — for example, Sales_Tax or First.Quarter.
How many characters? A name can contain up to 255 characters.
Note If a name defined for a range contains more than 253 characters, you cannot select it from the Name box.
Are names case sensitive? Names can contain uppercase and lowercase letters. Microsoft Excel does not distinguish between uppercase and lowercase characters in names. For example, if you have created the name Sales and then create another name called SALES in the same workbook, the second name will replace the first one.
end of Help Text
Let's look at naming ranges first.
There are many ways that we can use to name ranges in Excel. By far the quickest and easiest in most cases is to simply highlight the range of cells and type the name in the NameBox to the left of the formula bar. This, however, does limit us to naming ranges only, ie; you cannot use this method to name constants or formulas.
The other methods can be found by going to Insert>Name and selecting one of the options from the sub menu leading off from Name.
Let's look at each one of these in turn.
Define
When you select the Define option (or push Ctrl+F3) you will see the Define name dialog box. It is in this box that you will see a list of all Names in the Workbook. By selecting any one of these Names you will see the Worksheet and cell address they refer to in the Refer to box at the bottom of the Define name dialog box. If you place your mouse insertion point anywhere within the Refers To box while you have a name highlighted, you will be taken to that location. This is also where you would go to delete any redundant Names. You would do this by simply selecting the Name and clicking Delete.
The Define dialog box is arguably the most useful for naming as it is here you can write formulas for your ranges and the only limit is ones own imagination. See Dyna Ranges for some examples. It is also here that we can name Formulas so we can use them over and over again. These might be as simple as multiplying to constants or a deeply nested Formula. For example suppose you have a business with "x" number of employees and 5 different levels of pay rates. You could do the following.
In Cells A1 type the heading: Names. In B1 type the heading: Pay Rate
In Cells A2:A10 type any names eg; Bill L, John W etc. In B2:B10 type any pay rates eg; $14.25, $12.55 etc
Name the range A1:B10 PayRates, ie; select A1:B10 and type PayRates in the Name box (left of Formula bar)
Select cell D2 and go to Insert>Name>Define (Ctrl+F3)
Type: HrlyRate in the Names in workbook: box.
Type: =VLOOKUP(D1,PayRate,2,FALSE) in the Refers to: box
Click Add then OK.
Now type any name from the Names column into any cell.
In the cell directly below the name put the formula: =40*HrlyRate.
You will get the hourly rate for the person named in the cell directly above multiplied by 40. Whenever and wherever you use this formula it will always use the correct hourly rate for the name in the cell directly above.
This is just a simple example of the sort of things you can do with the Define name dialog. As you get better at writing formulas and using Excel Functions you can start to come up with very imaginative ways of doing this type of thing.
Paste
This dialog box (F3) can be used to either select the name you want from a list of all names within the Workbook or Paste a list of names and their associated references.
Lets say you were using the =40*HrlyRate formula in a cell and were a bit unsure of the name you had applied. You would type: =40 and then select HrlyRate from the list and click OK. Excel will insert the name for you.
If you use this dialog and select Paste list Excel will create a list of all the names in the Workbook in one column and all their associated references in the column to the right. Just make sure you don't have any data that will be replaced. If you do just use the Undo command (Ctrl+Z).
Create
This dialog (Ctrl+Shift+F3) will allow you to quickly use column or row headings as range names. Let's say you had a table set up on your Worksheet and you wanted to use the column headings as names for all the data below the heading. You would select the entire table (headings included) push Ctrl+Shift+F3, check the Top row CheckBox only and click OK. Excel will apply the names of each of your column headings and refer them to the data below the heading.
Lets say you have the names of 1000 employees in cells A2:A1002 and in cells B1:B10 you have the names of different locations that your employees need to travel to on a daily bases. Each time an employee travels to a particular location you put a tally in the intersecting cell of the Location and Employee name.
In other words, if Bill has been to New York five times this year, there would be a number 5 in the cell that intersects the column heading New York and the row heading Bill. Now Let's say that the pay office needs to know how many times Bill (or any employee) has been to New York (or any location). You could select the range A1:K1002 (your entire table) push Crtl+Shift+F3 and select the options Top row and Left column and click OK. Then in any cell you could type the formula: =Bill NewYork and Excel will return the value of the cell that intersects Bill and New York. You MUST push the Space bar after Bill. In other words you must have a space between Bill and NewYork.
Apply
This dialog box is used to replace cell references within formulas to their range names. Let's say you have been using a simple SUM function like: =SUM(A1:A100) throughout a Workbook. You then decide to name the range A1:A100 Totals. When you do so all your =SUM(A1:A100) formulas will still refer to the range address rather than its new name (Totals).
This is where you would use the Apply dialog box. You would simply activate it while you have a single cell selected and select the name: Totals and click OK. Excel will go through the Workbook and replace all formulas that are using the range A1:A100 with the name Totals. If you did the same with more than one cell selected, Excel will only replace references in the selected range. To apply more than one name hold down the shift key and select the names.
When we applied the name Totals, Excel by default will use absolute references ie; $A$1:$A$100. If we had a mix of absolute and relative references in our formulas ie; A1:A100 and $A$1:$A$100 we may only wish to replace the ones using $A$1:$A$100 (absolute references). In this case we would uncheck the Ignore Relative/Absolute Checkbox then click OK and Excel will only replace the reference $A$1:$A$100 with the name Totals. So basically clearing this check box will make Excel replace absolute references with absolute names, relative references with relative names, and mixed references with mixed names.
Leaving the Use row and column names box checked will force Excel to use the names of row and column ranges that refer to the cells if the exact names for the cells can't be found.
If you click the Options>>> button you will see
Omit column name if same column:
Replaces the reference with the row-oriented name without including the column name. Clear the check box if you want to include the column name.
Omit row name if same row:
Replaces the reference with the column-oriented name without including the row name. Clear the check box if you want to include the row name.
Name order:
Row column Column row
When a cell reference is replaced by both a row-oriented and a column-oriented range name, click Row column. Click Column row if you want the column name to appear first.
If you do not understand this it may become clear once you are familiar with Labels. See below. There is also a explanation with screen shots here http://193.144.38.110/manuais/excel97/ch06/ch06.htm under Applying Names to Formulas.
Label
If you have used numbers in your row and column headings such as years eg; 1995 Excel will use the numbers themselves instead of understanding you want to use a range named 1995.
To overcome this, you can create Labels. Let’s say that you have data on a worksheet as follows:
In F7 type: Vic
In G7 type: NSW
In H7 type: Tas
In J7 type: Total
In E9 type: 1995
In E10 type: 1996
In E11 type: 1997
In E12 type: 1998
In E13 type: 1999
Now fill your table with fictional numbers in the range F9:H13. Then:
Select cells E7:H13.
Go to Insert>Name>Label.
Click on Column labels in Add label range.
Click on Add to add the Labels.
Click on the Collapse Dialog button to shrink the dialog box. Select cells E9:E13
Click on Row labels in the expanded Label Ranges dialog box.
Click OK.
Now in cell J9 type: =sum(1995) and press Enter. Click in cell J9 again and you will see how the formula has automatically updated to include a Label for ‘1995’. Click in cell J10 and type: =sum(1996) and press Enter. Again you will see that the calculation is correct. You could also use your fill handle on cell J9 and drag down to cell J13 and Excel will automatically change the Label to be the appropriate year.
*If you go to Tools>Options/Calculations you will see an option to: Accept labels in formulas. If this option is not checked the above example would not work at all!*
So as we can see we can use Excels Filters (Advanced and Auto) to display virtually any criteria we want, so long as we have set up our table or list is a sensible manner. One aspect we have not mentioned about Filtered data is that Excel has a Function that is designed to work with a Filtered range. It is called SUBTOTAL and can be used to return the result of rows that are visible as the result of Filtering. There is a good description of this easy to use Function in the Excel help under: SUBTOTAL.
We can also use Names in our Workbooks that can not only make our formulas easy to read but also very easy to edit en masse. We can also use Names to create a formula that we may need to use often or is one that refers a table of data. The only real limit to this is our own imagination and determination.
OzGrid.com accepts no responsibility for any adverse affect that may result from undertaking our training.