How to AutoFilter a Table based on a Cell Value in Excel

This post will guide you how to auto filter a given range of cells based on a certain cell value in Excel 2013/2016. How do I use VBA Autofilter function to filter the data based on a cell value in Excel.

For example, you wish to quickly filter the data in range A1:B5 based on a cell value that you entered in A9, and then the data will be filtered automatically in range A1:B5. Of course, you can use the inbuilt filter functionality with copy-paste operations, and it will take you a lot of time to do it manually. So you can use VBA AutoFilter to filter data quickly so that to save your time.

AutoFilter a Table based on a Cell Value using VBA Macro


Just do the following steps:

Step1: Go to your worksheet that you want to create VBA AutoFilter macro to autofilter the data based on cell value that you typed.

autofilter based on cell value1

Step2: right click on the sheet tab in your current worksheet, and select View Code from the pop-up menu list, and then the Visual Basic for Application window will appear.

autofilter based on cell value2

Step3: you need to copy and paste the below VBA Macro code into the code window. And then close it.

Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.Address = Range("A9").Address Then
       Range("A1:B5").CurrentRegion.AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range("A8:A9")
   End If
End Sub

autofilter based on cell value3

Step4: type the first value “version” in Cell A8, and then type another value “2016” as a criteria, press Enter key.

Step5: you would see that your data is filtered based on cell value that you entered.

autofilter based on cell value4

autofilter based on cell value5

x
How to Unmerge Cells and Fill Down Values in Excel

Note: the range A1:B5 is your data that you want to filter out. And A8:A9 is your criteria range cells that will be filtered based on.

When you change the cell value in Cell A9, your data also be filtered based on cell value in A9 automatically.

 

 

 

 

Related Posts

VBA Macro For VLOOKUP From Another Sheet
vba macro for vlookup from another sheet1

In the previous post, you should know that how to fix or remove the #N/A error when using VLOOKUP formula to lookup value from another sheet. And this post will show you how to use VBA code to vlookup data ...

How To Insert Comments in Protected Worksheet in Excel
insert commetns in protected workshee3

This post will show you how to allow comments in a protected worksheet in Excel. You can easily to insert comments into cells in a normal worksheet in Excel, but if want to insert a comment in a worksheet that ...

How To Convert Text to Upper Cases(Using VBA) in Excel
convert text to upper cases1

This post will show you how to switch from lower case to upper case in Excel. and I am going to show you two different ways of converting text to upper cases using formula or VBA macro in Excel 2013,Excel ...

How To Hide Every Other Row in Excel (Using VBA)
hide every other row1

This post will show you how to hide alternate rows or columns in Excel or how to hide every third, fourth, fifth row or column in Excel. If you want to hide every other row in your current worksheet, how ...

How to Disable the Save As Prompt in Excel
disable save as prompt1

This post will show you how to use a VBA Macro to save an Excel file and overwrite any existing file without a prompt so that you are going to get the little window that says file already exists do ...

How to Count Cells that Contain even or odd numbers in Excel
count cells that contain even numbers5

This post will guide you how to count the number of cells that contain odd or even numbers within a range of cells using a formula in Excel 2013/2016.How do I count cells that contain odd numbers through the use ...

How to Count Cells that Contain negative Numbers in Excel

This post will guide you how to count the number of cells that contain negative numbers within a range of cells using a formula in Excel 2013/2016.You can count the number of negative numbers in your data using easy functions ...

How to Count Cells Are Not Blank or Empty in Excel
count non blank nonempty cells5

This post will guide you how to count cells that are not blank or empty in a given range cells using a formula in Excel 2013/2016.How do I count the number of cells that are not blank in a particular ...

How to Count Cells Less Than a Specific Value in Excel
count cells lessr than5

This post will guide you how to count the number of cells less than a particular numeric value in a given range cells using a formula in Excel 2013/2016. How do I count cells that are less than a specific ...

How to Count Cells Greater Than a Specific Value in Excel
count cells greater than 5

This post will guide you how to count the number of cells greater than a particular numeric value in a given range cells using a formula in Excel 2013/2016. How do I count cells that are greater than a specific ...

Sidebar