Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

How to autofilter rows based on cell value in Excel?

Normally, the Filter function in Excel can help us to filter any data as we need, but, sometimes, I would like to auto filter cells based on a manual cell input which means when I enter a criteria in a cell, the data can be filtered automatically at once. Are there any good ideas to deal with this job in Excel?

Auto filter rows based on cell value you entered with VBA code

Filter data by multiple criteria or other specific condition, such as by text length, by case sensitive


Auto filter rows based on cell value you entered with VBA code


Supposing, I have the following range of data, now, when I enter the criteria in cell E1 and E2, I want the data will be filtered automatically as below screenshot shown:

doc auto filter 1

1. Go the worksheet that you want to auto filter the date based on cell value you entered.

2. Right click the sheet tab, and select View Code from the context menu, in the popped out Microsoft Visual Basic for Applications window, please copy and paste the following code into the blank Module window, see screenshot:

VBA code: auto filter data according to entered cell value:

Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice 20160606
   If Target.Address = Range("E2").Address Then
       Range("A1:C20").CurrentRegion.AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range("E1:E2")
   End If
End Sub

doc auto filter 2

Note: In the above code, A1:C20 is your data range that you want to filter, E2 is the target value that you want to filter based on, and E1:E2 is your criteria cell will be filtered based on. You can change them to your need.

3. Now, when you entering the criteria in cell E1 and E2 and press Enter key, your data will be filtered by the cell values automatically.


Filter data by multiple criteria or other specific condition, such as by text length, by case sensitive

Filter data by multiple criteria or other specific condition, such as by text length, by case sensitive, etc.

Kutools for Excel’s Super Filter feature is a powerful utility, you can apply this feature to finish the following operations:

  • Filter data with multiple criteria;              Filter data by text length;
  • Filter data by upper / lower case;             Filter date by year / month / Day / week / quarter

doc-super-filter1

Kutools for Excel: with more than 200 handy Excel add-ins, free to try with no limitation in 60 days. Download and free trial Now!


Demo: Auto filter rows based on cell value you entered with VBA code


Recommended Productivity Tools

Ribbon of Excel (with Kutools for Excel installed)

300+ Advanced Features Increase Your Productivity by 71%, and Help You To Stand Out From Crowd!

Would you like to complete your daily work quickly and perfectly? Kutools For Excel brings 300+ cool and powerful advanced features (Combine workbooks, sum by color, split cell contents, convert date, and so on...) for 1500+ work scenarios, helps you solve 82% Excel problems.

  •  Deal with all complicated tasks in seconds, help to enhance your work ability, get success from the fierce competition, and never worry about being fired.
  •  Save a lot of work time, leave much time for you to love and care the family and enjoy a comfortable life now.
  •  Reduce thousands of keyboard and mouse clicks every day, relieve your tired eyes and hands, and give you a healthy body.
  •  Become an Excel expert in 3 minutes, and get admiring glance from your colleagues or friends.
  •  No longer need to remember any painful formulas and VBA codes, have a relaxing and pleasant mind, give you a thrill you've never had before.
  •  Spend only $39, but worth than $4000 training of others. Being used by 110,000 elites and 300+ well-known companies.
  •  60-day unlimited free trial. 60-day money back guarantee. Free upgrade and support for 2 years. Buy once, use forever.
  •  Change the way you work now, and give you a better life immediately!

Office Tab Brings Efficient And Handy Tabs to Office (include Excel), Just Like Chrome, Firefox, And New IE

  • Increases your productivity by 50% when viewing and editing multiple documents.
  • Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
  • Open and create documents in new tabs of same window, rather than in new windows.
  • Help you work faster and easily stand out from the crowd! One second to switch between dozens of open documents!
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Robert · 3 months ago
    So I have a bunch of values and then a table of data. I am wondering if I can filter that table based on the values similarly to what is explained above. For example I would like to click on a cell that has the value of 3, which corresponds to 3 records(200 rows, 25 columns) that meet a condition and then have my table filtered to just show those records. An example of a condition would be, if one variable is great than 100. I have over 100 of these conditions which is why I would like my table to be linked to it in some way. Any help would be much appreciated. In your example provided, it would be similar to if you just wanted all ages over 3, 6, 9, 12 etc and then you had 25 similar variables.So to filter the table to show only records with age over 3 based on clicking a value from a list that says something like age>3 - 2 records, age>6 - 4 records etc
  • To post as a guest, your comment is unpublished.
    Elliott · 3 months ago
    Is there a way to have it continue to filter with additional boxes. When I write it as ElseIf, it only follows the ElseIf command.
  • To post as a guest, your comment is unpublished.
    murat yazici · 4 months ago
    Private Sub Worksheet_Change(ByVal Target As Range)
    'Updateby Extendoffice 20160606
    If Target.Address = Range("E2").Address Then
    Range("A1:C20").CurrentRegion.AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range("E1:E2")
    End If
    End Sub


    E2 HUCRESI YERINE E SUTUNUNUNA YAZILAN SON SATIRA GORE FILITRELEME YAPABILIR MI


    According the code mentioned above , is it possible to make filtration according the written data to the last row of column E ?


    I hope to get help and thanks for your help
    • To post as a guest, your comment is unpublished.
      skyyang · 4 months ago
      Hi, murat,
      The above code works well in the whole worksheet, you just need to change the cell references to your need. Please try it, thank you!
  • To post as a guest, your comment is unpublished.
    Kent · 4 months ago
    The VB script worked beautifully. Many thanks for the post!
  • To post as a guest, your comment is unpublished.
    Bob · 4 months ago
    What happens if you have GRADE11 and GRADE12 for example. Will the filter show these also if you try and filter
    on GRADE1?
    • To post as a guest, your comment is unpublished.
      skyyang · 4 months ago
      Hello, Bob,
      Yes, as you said, when entering part of the text you want to filter, all the cells contain the part text will be filtered out. So, if you type Grade1, all cells contain Grade1, Grade11, Grage123...will be filtered out.