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

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

Find and Replace Multiple Values

This post will guide you how to find and replace multiple values at once with VBA macro or using formula  in Excel. How do I make multiple find and replace in Excel. Suppose that you have a few cells containing ...

VBA Macro For VLOOKUP From Another Sheet

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

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

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)

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 ...

Sidebar