+ Reply to Thread
Results 1 to 11 of 11

AutoFilter: Array as Criteria

  1. #1
    Registered User
    Join Date
    09-17-2013
    Location
    East
    MS-Off Ver
    Excel 2010
    Posts
    55

    AutoFilter: Array as Criteria

    Hey folks,

    I deal with the autofilter-method in VBA for the first time and it worked quite well as long as I gave it single values as a criteria. Now I want to give it an array. First I fill the array with some weekdaynumber which works great.

    The array is then wochentage(0 To 2) and contains the values (1, 2, 3). All the values exist in the corresponding column, that I want to filter (I ensure that by some more code, that I deleted for better overview).

    Please Login or Register  to view this content.

    The code runs, but just the entries with "3" are selected (see attached screenshot).
    Unbenannt.png

    What do I do wrong?

    Thanks for you help!
    Klaster

  2. #2
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,700

    Re: AutoFilter: Array as Criteria

    Try this.
    Please Login or Register  to view this content.
    You must specify the Operator, usually it's optional.

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

    Re: AutoFilter: Array as Criteria

    Or
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    09-17-2013
    Location
    East
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: AutoFilter: Array as Criteria

    Thanks for you replies. I tried the xlFilterValues-Option, however, the result was that whenever the arraysize is 1, wrong outputs are given. ??

    For bigger arrays, nothing is selected in the autofilter now (see screenshot). Here is my adapted code:
    Please Login or Register  to view this content.
    The related Debug.Print shows, that 1, 2 and 3 are in the array:
    Please Login or Register  to view this content.
    It shouldn't matter, HOW I fill the array, should it?

    Unbenannt2.png
    Last edited by Klaster; 04-10-2014 at 11:47 AM. Reason: inserted screenshot

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

    Re: AutoFilter: Array as Criteria

    Please Login or Register  to view this content.
    is nothing to do with array and resizing. It uses an array as a tool for multi-selection on the same field.

  6. #6
    Registered User
    Join Date
    09-17-2013
    Location
    East
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: AutoFilter: Array as Criteria

    Hey AB33,

    I use the autofilter-method within a function. I wanted to give the "wochendtage"-array to the function so it can be used in it. Do I understand you correctly, that this is not possible?

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

    Re: AutoFilter: Array as Criteria

    The way you constructed does not work with auto filter, it might work with advanced filter.

    You can try this way, but only one loop at a time, it does not work on multi-dimensional array

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    09-17-2013
    Location
    East
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: AutoFilter: Array as Criteria

    okay, then I'll fall back to the loop-through-array-solution. Thanks for you help!

  9. #9
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,787

    Re: AutoFilter: Array as Criteria

    Even if you problem is marked "Solved" perhaps this link could be of interest?

    http://blog.contextures.com/archives...ia-in-a-range/

    Alf

  10. #10
    Registered User
    Join Date
    09-17-2013
    Location
    East
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: AutoFilter: Array as Criteria

    Hey Alf,
    indeed naming a range with the according numbers in it might have been a solution! Won't touch my (running) solution anymore, but I'm sure your reply will be helpful for others!
    Cheers,
    Klaster

  11. #11
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,008

    Re: AutoFilter: Array as Criteria

    You don't need to loop for the filter:
    Please Login or Register  to view this content.
    Everyone who confuses correlation and causation ends up dead.

+ 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. [SOLVED] Using an array from a range for Autofilter Criteria
    By J-Tin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-31-2013, 10:49 AM
  2. Replies: 4
    Last Post: 03-16-2013, 08:33 AM
  3. AutoFilter Multiple Criteria Array
    By erock24 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-02-2013, 04:33 AM
  4. Autofilter using array as criteria = Run time error
    By postelrich in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-25-2011, 05:02 PM

Tags for this Thread

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