How do you use AutoFilter to display only records where the value is?

This free Excel macro filters data to display only those records or rows that contain a value between two values. For example, you could display all of the salesmen whose sales are between $50,000 and $75,000 for the quarter. You can use any number and apply it to any data set that contains number where you need to display all of the records that are within a certain range.

To use this macro, just replace "50000" with the number you want to use for the lower end of the range and replace "75000" with the number that you would like to use for the upper end of the range. Make sure to leave the ">" and "<" in place because this is what makes the macro work.

How Filter Macros Work

All of the elements below often appear within autofilter macros.

Range

  • This should be the start of the data set, table, or list which you would like to filter. This can also be the entire range reference to the table. For example, if the table was from cell A1:D450, you could put that as the range or you could put A1 as the range. You can do this because the autofilter feature in Excel will automatically try to determine the total range which you would like to filter.

Field

  • This is the number of the column within the data table that you would like to filter. The first field (1) is the very first column in the data set that will be filtered. This means that if your data starts in column B and your range is Range("B1") and you want to filter based on column D, you would put 3 in for the field.

Criteria

  • This is the criteria by which you would like to filter. Some of the macros have symbols within the quotation marks after this argument and those symbols (such as <,>,*,?, etc.) should be left where they are in order to retain the functionality of the macro.

Operator

  • You will not have to change this. This is simply the way to perform different types of filter features in Excel.

Where to install the macro:  Module

Excel Macro to Filter Data in Excel to Display Records that Contain a Value Between Two Values - AutoFilter.

Sub AutoFilter_in_Excel_Above_Below_Num() 'This autofilter macro displays records with a number between 50000 and 75000 within the first field - in this case in column A 'It is important to retain the ">" and "<" signs within this macro because that it what makes this work correctly Range("A1").AutoFilter Field:=1, Criteria1:=">50000", Operator:=xlAnd, Criteria2:="<75000" End Sub


How do you use AutoFilter to display only records where the value is?

Excel VBA Course - From Beginner to Expert

200+ Video Lessons 50+ Hours of Instruction 200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course


How to Install the Macro

  1. Select and copy the text from within the grey box above.

  2. Open the Microsoft Excel file in which you would like the Macro to function.

  3. Press "Alt + F11" - This will open the Visual Basic Editor - Works for all Excel Versions.  Or For other ways to get there, Click Here.

  4. On the new window that opens up, go to the left side where the vertical pane is located. Locate your Excel file; it will be called VBAProject (YOUR FILE'S NAME HERE) and click this.

  5. If the Macro goes in a Module, Click Here, otherwise continue to Step 8.

  6. If the Macro goes in the Workbook or ThisWorkbook, Click Here, otherwise continue to Step 8.

  7. If the Macro goes in the Worksheet Code, Click Here, otherwise continue to Step 8.

  8. Close the Microsoft Visual Basic Editor window and save the Excel file. When you close the Visual Basic Editor window, the regular Excel window will not close.

  9. You are now ready to run the macro.

How do you use AutoFilter to display only records where the value is?

Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Lesson 20: Filtering Data

/en/excel2016/sorting-data/content/

Introduction

If your worksheet contains a lot of content, it can be difficult to find information quickly. Filters can be used to narrow down the data in your worksheet, allowing you to view only the information you need.

Optional: Download our practice workbook.

Watch the video below to learn more about filtering data in Excel.

To filter data:

In our example, we'll apply a filter to an equipment log worksheet to display only the laptops and projectors that are available for checkout.

  1. In order for filtering to work correctly, your worksheet should include a header row, which is used to identify the name of each column. In our example, our worksheet is organized into different columns identified by the header cells in row 1: ID#, Type, Equipment Detail, and so on.

    How do you use AutoFilter to display only records where the value is?

  2. Select the Data tab, then click the Filter command.

    How do you use AutoFilter to display only records where the value is?

  3. A drop-down arrow will appear in the header cell for each column.
  4. Click the drop-down arrow for the column you want to filter. In our example, we will filter column B to view only certain types of equipment.

    How do you use AutoFilter to display only records where the value is?

  5. The Filter menu will appear.
  6. Uncheck the box next to Select All to quickly deselect all data.

    How do you use AutoFilter to display only records where the value is?

  7. Check the boxes next to the data you want to filter, then click OK. In this example, we will check Laptop and Projector to view only these types of equipment.

    How do you use AutoFilter to display only records where the value is?

  8. The data will be filtered, temporarily hiding any content that doesn't match the criteria. In our example, only laptops and projectors are visible.

    How do you use AutoFilter to display only records where the value is?

Filtering options can also be accessed from the Sort & Filter command on the Home tab.

How do you use AutoFilter to display only records where the value is?

To apply multiple filters:

Filters are cumulative, which means you can apply multiple filters to help narrow down your results. In this example, we've already filtered our worksheet to show laptops and projectors, and we'd like to narrow it down further to only show laptops and projectors that were checked out in August.

  1. Click the drop-down arrow for the column you want to filter. In this example, we will add a filter to column D to view information by date.

    How do you use AutoFilter to display only records where the value is?

  2. The Filter menu will appear.
  3. Check or uncheck the boxes depending on the data you want to filter, then click OK. In our example, we'll uncheck everything except for August.

    How do you use AutoFilter to display only records where the value is?

  4. The new filter will be applied. In our example, the worksheet is now filtered to show only laptops and projectors that were checked out in August.

    How do you use AutoFilter to display only records where the value is?

To clear a filter:

After applying a filter, you may want to remove—or clear—it from your worksheet so you'll be able to filter content in different ways.

  1. Click the drop-down arrow for the filter you want to clear. In our example, we'll clear the filter in column D.

    How do you use AutoFilter to display only records where the value is?

  2. The Filter menu will appear.
  3. Choose Clear Filter From [COLUMN NAME] from the Filter menu. In our example, we'll select Clear Filter From "Checked Out".

    How do you use AutoFilter to display only records where the value is?

  4. The filter will be cleared from the column. The previously hidden data will be displayed.

    How do you use AutoFilter to display only records where the value is?

To remove all filters from your worksheet, click the Filter command on the Data tab.

How do you use AutoFilter to display only records where the value is?

Advanced filtering

If you need a filter for something specific, basic filtering may not give you enough options. Fortunately, Excel includes many advanced filtering tools, including search, text, date, and number filtering, which can narrow your results to help find exactly what you need.

To filter with search:

Excel allows you to search for data that contains an exact phrase, number, date, and more. In our example, we'll use this feature to show only Saris brand products in our equipment log.

  1. Select the Data tab, then click the Filter command. A drop-down arrow will appear in the header cell for each column. Note: If you've already added filters to your worksheet, you can skip this step.
  2. Click the drop-down arrow for the column you want to filter. In our example, we'll filter column C.

    How do you use AutoFilter to display only records where the value is?

  3. The Filter menu will appear. Enter a search term into the search box. Search results will appear automatically below the Text Filters field as you type. In our example, we'll type saris to find all Saris brand equipment. When you're done, click OK.

    How do you use AutoFilter to display only records where the value is?

  4. The worksheet will be filtered according to your search term. In our example, the worksheet is now filtered to show only Saris brand equipment.

    How do you use AutoFilter to display only records where the value is?

To use advanced text filters:

Advanced text filters can be used to display more specific information, like cells that contain a certain number of characters or data that excludes a specific word or number. In our example, we'd like to exclude any item containing the word laptop.

  1. Select the Data tab, then click the Filter command. A drop-down arrow will appear in the header cell for each column. Note: If you've already added filters to your worksheet, you can skip this step.
  2. Click the drop-down arrow for the column you want to filter. In our example, we'll filter column C.

    How do you use AutoFilter to display only records where the value is?

  3. The Filter menu will appear. Hover the mouse over Text Filters, then select the desired text filter from the drop-down menu. In our example, we'll choose Does Not Contain to view data that does not contain specific text.

    How do you use AutoFilter to display only records where the value is?

  4. The Custom AutoFilter dialog box will appear. Enter the desired text to the right of the filter, then click OK. In our example, we'll type laptop to exclude any items containing this word.

    How do you use AutoFilter to display only records where the value is?

  5. The data will be filtered by the selected text filter. In our example, our worksheet now displays items that do not contain the word laptop.

    How do you use AutoFilter to display only records where the value is?

To use advanced number filters:

Advanced number filters allow you to manipulate numbered data in different ways. In this example, we'll display only certain types of equipment based on the range of ID numbers.

  1. Select the Data tab on the Ribbon, then click the Filter command. A drop-down arrow will appear in the header cell for each column. Note: If you've already added filters to your worksheet, you can skip this step.
  2. Click the drop-down arrow for the column you want to filter. In our example, we'll filter column A to view only a certain range of ID numbers.

    How do you use AutoFilter to display only records where the value is?

  3. The Filter menu will appear. Hover the mouse over Number Filters, then select the desired number filter from the drop-down menu. In our example, we'll choose Between to view ID numbers between a specific number range.

    How do you use AutoFilter to display only records where the value is?

  4. The Custom AutoFilter dialog box will appear. Enter the desired number(s) to the right of each filter, then click OK. In our example, we want to filter for ID numbers greater than or equal to 3000 but less than or equal to 6000, which will display ID numbers in the 3000-6000 range.

    How do you use AutoFilter to display only records where the value is?

  5. The data will be filtered by the selected number filter. In our example, only items with an ID number between 3000 and 6000 are visible.

    How do you use AutoFilter to display only records where the value is?

To use advanced date filters:

Advanced date filters can be used to view information from a certain time period, such as last year, next quarter, or between two dates. In this example, we'll use advanced date filters to view only equipment that has been checked out between July 15 and August 15.

  1. Select the Data tab, then click the Filter command. A drop-down arrow will appear in the header cell for each column. Note: If you've already added filters to your worksheet, you can skip this step.
  2. Click the drop-down arrow for the column you want to filter. In our example, we'll filter column D to view only a certain range of dates.

    How do you use AutoFilter to display only records where the value is?

  3. The Filter menu will appear. Hover the mouse over Date Filters, then select the desired date filter from the drop-down menu. In our example, we'll select Between to view equipment that has been checked out between July 15 and August 15.

    How do you use AutoFilter to display only records where the value is?

  4. The Custom AutoFilter dialog box will appear. Enter the desired date(s) to the right of each filter, then click OK. In our example, we want to filter for dates after or equal to July 15, 2015, and before or equal to August 15, 2015, which will display a range between these dates.

    How do you use AutoFilter to display only records where the value is?

  5. The worksheet will be filtered by the selected date filter. In our example, we can now see which items have been checked out between July 15 and August 15.

    How do you use AutoFilter to display only records where the value is?

Challenge!

  1. Open our practice workbook.
  2. Click the Challenge tab in the bottom-left of the workbook.
  3. Apply a filter to show only Electronics and Instruments.
  4. Use the Search feature to filter item descriptions that contain the word Sansei. After you do this, you should have six entries showing.
  5. Clear the Item Description filter.
  6. Using a number filter, show loan amounts greater than or equal to $100.
  7. Filter to show only items that have deadlines in 2016.
  8. When you're finished, your workbook should look like this:

    How do you use AutoFilter to display only records where the value is?

/en/excel2016/groups-and-subtotals/content/

How do you filter a table to show only the rows where the value is?

Click a cell in the range or table that you want to filter. On the Data tab, click Filter. in the column that contains the content that you want to filter. Under Filter, click Choose One, and then enter your filter criteria.

How do you AutoFilter based on cell value?

To apply a filter for a cell's value: Right-click a cell that contains the value you want to filter for. Choose Filter > Filter by Selected Cell's Value. The filter will be applied to the column.

How do you filter data by value?

You can right-click a particular cell in a column to open the shortcut menu for that value. Point to the small filter icon, and then select the filter option you want to use. Power Query displays a type-specific filter based on the data type of the column.