+ Reply to Thread
Results 1 to 9 of 9

AutoFilter: Setting Criteria1 to an Array for "Any of these words" type filtering

  1. #1
    Registered User
    Join Date
    07-05-2013
    Location
    Rochester, NY
    MS-Off Ver
    Office 2010
    Posts
    4

    Angry AutoFilter: Setting Criteria1 to an Array for "Any of these words" type filtering

    Greetings!

    I have a "Keywords" field and am using AutoFilter to support three types of "searches" (filters):
    1. All of these words
    2. This exact word or phrase
    3. Any of these words

    The first two seem to be working fine, however I can't seem to get the last ("Any of these words") to work...any help would be much appreciated!

    Please Login or Register  to view this content.
    Note that the MsgBox line I've commented out returns the correct values...thus I suspect it's something to do with the "r.AutoFilter Field:=2, Criteria1:=searchTerms, Operator:=xlFilterValues" line I've bolded above.

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: AutoFilter: Setting Criteria1 to an Array for "Any of these words" type filtering

    "The first two seem to be working fine"

    Arrays Can ONLY take 2 elements. The same with OR and AND operators.

  3. #3
    Registered User
    Join Date
    07-05-2013
    Location
    Rochester, NY
    MS-Off Ver
    Office 2010
    Posts
    4

    Re: AutoFilter: Setting Criteria1 to an Array for "Any of these words" type filtering

    AB33 - I'm sorry if I wasn't clear...what I meant is: the first two types of filters are working (1. All of these words, 2. This exact word or phrase); the third type (3. Any of these words) doesn't work at all. It sounds like you're saying that the searchTerms array can only be two elements--and thus any additional elements would be thrown out--however that filter returns 0 results, even if there is only one element in the array (e.g. if one were to enter "Test" in the Keywords field).

    Am I missing something, or did I misinterpret your response?

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: AutoFilter: Setting Criteria1 to an Array for "Any of these words" type filtering

    That is right, can only take two values, but the syntax might not be right. This line gives some idea.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    07-05-2013
    Location
    Rochester, NY
    MS-Off Ver
    Office 2010
    Posts
    4

    Re: AutoFilter: Setting Criteria1 to an Array for "Any of these words" type filtering

    Removed duplicate post.
    Last edited by sheldonbeswift; 07-15-2013 at 12:29 PM. Reason: Duplicate post due to server error.

  6. #6
    Registered User
    Join Date
    07-05-2013
    Location
    Rochester, NY
    MS-Off Ver
    Office 2010
    Posts
    4

    Re: AutoFilter: Setting Criteria1 to an Array for "Any of these words" type filtering

    AB33 - Based on the following, my syntax appears to be correct (I've tried putting searchTerms in quotes, but that didn't work either): http://msdn.microsoft.com/en-us/libr.../ff194617.aspx

    Please Login or Register  to view this content.
    I must be missing something....when I enter the keyword "Keyword1", the filter is Equals "Keyword1". If I enter the keywords "Keyword1 Keyword2", the filter Equals "Keyword2" (the filter is aways Equals [the last keyword]). In both examples I would expect to see "Contains" (versus Equals), and in the latter example I would expect to see Contains "Keyword1" or Contains "Keyword2".

    Attachment 250336
    Last edited by sheldonbeswift; 07-15-2013 at 12:25 PM.

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: AutoFilter: Setting Criteria1 to an Array for "Any of these words" type filtering

    There is a problem with the attachment, I could not open it.

    Please Login or Register  to view this content.
    Is filtering not ranges, but a single range A1, which is the heading for filter.

  8. #8
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: AutoFilter: Setting Criteria1 to an Array for "Any of these words" type filtering

    can you post the attachment again? your original code works ok for me-assuming your autofilter range does have two columns ;-)
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  9. #9
    Registered User
    Join Date
    07-05-2013
    Location
    Rochester, NY
    MS-Off Ver
    Office 2010
    Posts
    4

    Re: AutoFilter: Setting Criteria1 to an Array for "Any of these words" type filtering

    JosephP - Sure, please see attached. The original code works, just not the way I want it to ("Any of these words" should be filter on Contains "Keyword1 or Contains "Keyword2" or Contains "Keyword3").

    7-15-2013 11-53-04 AM.jpg

  10. #10
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: AutoFilter: Setting Criteria1 to an Array for "Any of these words" type filtering

    a picture is of no use I'm afraid

    however-you cannot use an array for 'contains' in an autofilter-it has to be an exact match on the array elements

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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