+ Reply to Thread
Results 1 to 10 of 10

Test if the autofilter found the criteria values ?

  1. #1
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Test if the autofilter found the criteria values ?

    Hi

    Column A contains
    Apple
    Mango
    Grapes
    repeatedly

    I set the criteria for autofilter as "Orange"
    obviously Orange is not found in the column and the range is not filtered,but how can I test if it did not find "Orange" and the column is not not filtered.

    Reason I why I need this:

    I am applying autofilter on two column on my data set but if the first column is not filtered (did not found the criteria) I don't want to apply filter on other column

    Hope this makes sense and doesn't need a sample book

    Help would be greatly appreciated
    Best Regards

    Imran Bhatti
    Teach me Excel VBA

  2. #2
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Test if the autofilter found the criteria values ?

    You can check whether the item (e.g. Orange) is exists before applying autofilter, if it is exists then do autofilter, if not exists then don't autofilter.
    Please Login or Register  to view this content.
    1. I care dog
    2. I am a loop maniac
    3. Forum rules link : Click here
    3.33. Don't forget to mark the thread as solved, this is important

  3. #3
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: Test if the autofilter found the criteria values ?

    Correct.But what if the criteria is an array?

  4. #4
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Test if the autofilter found the criteria values ?

    Considering your description, easiest approach would be, filter the first column and then check the filtered cells count for that column including the header row and if the cells count is greater than 1, that means it found the criteria in that column and if the cells count is 1, it means criteria was not found and you can remove the filter from that column and skip the autofiltering the second column.

    Like this...
    Please Login or Register  to view this content.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  5. #5
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: Test if the autofilter found the criteria values ?

    @sktneer (Guru j)
    Solutions by Karedog and you are good for single word criteria. The only thing left is what I have made red in your code.

    Please Login or Register  to view this content.

  6. #6
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Test if the autofilter found the criteria values ?

    @ Imran
    The type of criteria here doesn't make any difference. The point is to check the count of visible cells after applying the filter to the first column no matter what the criteria is.

  7. #7
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Test if the autofilter found the criteria values ?

    Or if you want to filter the second column only if all the items in criteria array are found in column A, you may try something like this...


    Please Login or Register  to view this content.

  8. #8
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Test if the autofilter found the criteria values ?

    To check if the criteria is an array :
    Please Login or Register  to view this content.
    Attached Files Attached Files

  9. #9
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: Test if the autofilter found the criteria values ?

    Now the Excel Gurus gone wild.
    Nice @Karodog and sktneer

    Now I have both the options
    1: if all items of array exist in column
    2: if any of item of array exists in column then
    filter other column

    Much appreciated

  10. #10
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Test if the autofilter found the criteria values ?

    You're welcome Imran! Glad we could help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Use multiple cell values in autofilter criteria
    By Dyordedgar in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 09-02-2016, 09:50 AM
  2. [SOLVED] Test Vlookup to see if value was found
    By anrichards22 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-30-2016, 09:22 PM
  3. Replies: 5
    Last Post: 09-01-2014, 08:05 AM
  4. [SOLVED] Macro to test which row the autofilter is currently set on
    By razz0807 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-24-2011, 12:26 PM
  5. Test for no valid criteria in autofilter
    By 1eyedjack in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-21-2010, 07:23 AM
  6. Test if search was found
    By PBM in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-20-2009, 09:07 AM
  7. avg test failed or no virus found
    By Greg in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-23-2005, 10:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1