+ Reply to Thread
Results 1 to 8 of 8

Using an array as criteria in an AutoFilter

  1. #1
    Forum Contributor
    Join Date
    03-05-2007
    Location
    Portsmouth, VA now, Falmouth, VA 4 yrs, Palm Bay, FL for 2 yrs, was Colorado Springs, CO for ten years; Cedark Park, TX; Zeeland, MI; Wilmette, IL; Princeton Junction, NJ; NY, NY
    MS-Off Ver
    365
    Posts
    617

    Using an array as criteria in an AutoFilter

    I thought if I could resolve some pieces then everything would fall into place, but this just isn't my day-

    Why does the following not work???

    Please Login or Register  to view this content.
    tblHistory is a table which in column #4 has student numbers.

    The two arrays, the first raw and the second transposed, appear as:
    Arrays.PNG
    and the student numbers in tblHistory are of "General" data type.

    This is my first attempt to understand how to use arrays in an AutoFilter, I apologize for all the questions. I have tried copying code from web pages, but what seems to have worked for others just won't work for me. If for Criteria1 I substitute Array("20584658","20586069") and as many more that I include, it works fine. Am I running into some datatype issue I need to correct for?

  2. #2
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Using an array as criteria in an AutoFilter

    Howdy.....just a quick question....when you say it doesn't work....do you get an error? or unexpected results?....and if unexpected, what as it and what should it be?
    Ernest

    Please consider adding a * if I helped

    Nothing drives me crazy - I'm always close enough to walk....

  3. #3
    Forum Contributor
    Join Date
    03-05-2007
    Location
    Portsmouth, VA now, Falmouth, VA 4 yrs, Palm Bay, FL for 2 yrs, was Colorado Springs, CO for ten years; Cedark Park, TX; Zeeland, MI; Wilmette, IL; Princeton Junction, NJ; NY, NY
    MS-Off Ver
    365
    Posts
    617

    Re: Using an array as criteria in an AutoFilter

    The entire chart gets wiped out as if nothing matched.

    I have narrowed it down to having something to do with data types.

    The source array cells which are to be used as the criteria1 array are actually populated with a vlookup formula displaying the Student Identification Numbers, which gets the student numbers from a master table Worksheets("History_").Range("tblHistory"), which is all records,.

    Though I have tried a number of attempts to convert these to string or text, I have discovered many ways that it won't work. (That was trying to put a positive spin on a negative).

    The student numbers are the only definitive record identity I have, for names get muddled with middle initials, Jr.'s and Sr.'s, and other weirdisms.

    Running what I have on an alternate test set of tables ran fine when I based it on text fields. What I finally condensed down to use (just to eliminate all the variables was:

    Please Login or Register  to view this content.
    and I verified column 4 as being the Student ID fields. Worksheets("George") is the sheet devoted to instructor Mr. George and SID is a column in his table of Student ID numbers that actually have the afore cited lookup function.

    I get the feeling I am headed to copying the vlookup colum to a colum of text values in order to have a chance to make this work, but if there is another method that won't have me adding columns and basically duplicating data, I SURE would like to know of it...

    Edit: Not even copying the list and formatting it to text worked. Now, even worse, I suspect I need to use an Advanced Filter, copy the visible cells to a new sheet, then sub-filter those with an auto filter. I feel really stupid, but at least it will work until someone educates me...
    Last edited by brucemc777; 07-25-2014 at 02:53 PM.

  4. #4
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Using an array as criteria in an AutoFilter

    if you believe the problem to be that the SID is a number and not text, try cancatenating a "' ' " in front of the number. that's the character below the double quotes. If you are using a VLOOKUP then you can try something like

    ="'"&VLOOKUP(...........................)

    I haven't tested this, just a shot in the dark....

  5. #5
    Forum Contributor
    Join Date
    03-05-2007
    Location
    Portsmouth, VA now, Falmouth, VA 4 yrs, Palm Bay, FL for 2 yrs, was Colorado Springs, CO for ten years; Cedark Park, TX; Zeeland, MI; Wilmette, IL; Princeton Junction, NJ; NY, NY
    MS-Off Ver
    365
    Posts
    617

    Re: Using an array as criteria in an AutoFilter

    I like the idea; might be a couple days before I am back in the office but look forward to giving it a try. WIll report back!

  6. #6
    Forum Contributor
    Join Date
    03-05-2007
    Location
    Portsmouth, VA now, Falmouth, VA 4 yrs, Palm Bay, FL for 2 yrs, was Colorado Springs, CO for ten years; Cedark Park, TX; Zeeland, MI; Wilmette, IL; Princeton Junction, NJ; NY, NY
    MS-Off Ver
    365
    Posts
    617

    Re: Using an array as criteria in an AutoFilter

    Uhg. It was well worth the shot. First, it simply showed the formula in the cell so I changed it from being "Text" to being "General". Then I pressed F2 to re-assess the cell and instead of presenting the "number" in text format, it shows the ' in front of the number, as in '20584659
    What a PITBS (Pain in the back-side).
    I don't think Excel likes me anymore...

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

    Re: Using an array as criteria in an AutoFilter

    Use Strings:
    Please Login or Register  to view this content.
    for example.
    Everyone who confuses correlation and causation ends up dead.

  8. #8
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Using an array as criteria in an AutoFilter

    hi brucemc777, option

    Please Login or Register  to view this content.

+ 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] AutoFilter: Array as Criteria
    By Klaster in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-10-2014, 06:36 PM
  2. [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
  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

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