+ Reply to Thread
Results 1 to 11 of 11

Set autofilter criteria based on changing array

  1. #1
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Set autofilter criteria based on changing array

    Hi guys and girls,

    I have a sheet where I need to place an autofilter.
    Criteria1 is fixed as always being just 1 criteria and always a product number.
    Criteria2 is flexible and comes from the products which are related to criteria 1.

    I set a filter on a sheet on criteria 1 and subsequently I have a column where just the related products are visible.
    How can I capture only the visible values so that I can put

    Please Login or Register  to view this content.
    Can I store the related products in a variable and just say Criteria2:=Array(relproducts) or something?

    I know it's a bit vague, but I hope you catch my drift!
    Thanks,

    Jasper
    Last edited by alansidman; 04-15-2015 at 08:46 AM.

  2. #2
    Forum Contributor LokeshKumar's Avatar
    Join Date
    03-31-2015
    Location
    India
    MS-Off Ver
    All, mostly 2010 now..
    Posts
    471

    Re: Set autofilter criteria based on changing array

    Hey
    Upload the sample sheet will do some change as per you
    Lokesh Kumar
    Stay Hungry.. Stay Foolish..
    _________________________________________________________
    Please Click STAR to Add Reputation if my/someone's answer helped!

  3. #3
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Set autofilter criteria based on changing array

    I can't upload a sample.
    I'm trying to do something like this:

    Please Login or Register  to view this content.
    Where rng = $B$2:$B$116193

    But this doesn't work... What am I doing wrong here?

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

    Re: Set autofilter criteria based on changing array

    Please Login or Register  to view this content.
    Excel treats the visible cells as "Areas", so you only get the areas value, it may be 1 or 2 rows in to an array.
    What I have not tried is if excel accepts a range and an array filter on a single row- filter. I am not sure if this also is the issue.
    Last edited by AB33; 04-15-2015 at 09:53 AM.

  5. #5
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Set autofilter criteria based on changing array

    Hi AB33,

    correct, I only get 1 value - I also try to do something like this:
    Please Login or Register  to view this content.
    To no avail, even though rng2 is now set as :
    $F$47147,$F$47362,$F$47634,$F$48035,$F$48490,$F$48892,$F$49350,$F$49753,$F$50211,$F$50616,$F$51075,$F$51480,$F$51939,$F$52344,$F$52801,$F$53205,$F$53658,$F$54062,$F$54512,$F$54916,$F$55366,$F$55772,$F$56226,$F$56650,$F$57100,$F$57507,$F$57969,$F$58388

    I thought I had to transpose them as well (application.transpose(rng2.value)) but that doesn't work either.
    How would I go around this?

    Or do I have to run a quick loop on rng2 and just manually add those values into an array? But if I do that, what would be the syntax?

  6. #6
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Set autofilter criteria based on changing array

    Store the particular column/Field visible cells values in an array and use xlFilterValues in operator


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

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

    Re: Set autofilter criteria based on changing array

    JasperD,
    You can cheat excel, but not the way you tried it. One other option is to copy the visible cells in to a sheet- as a range- and convert this values in to an array.
    Last edited by AB33; 04-15-2015 at 10:49 AM.

  8. #8
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Set autofilter criteria based on changing array


  9. #9
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Set autofilter criteria based on changing array

    Quote Originally Posted by :) Sixthsense :) View Post
    Store the particular column/Field visible cells values in an array and use xlFilterValues in operator
    Hi SixthSense,

    thanks for your reply! This is exactly what I want, but how do I store the particulare visible cells values into an array?

  10. #10
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Set autofilter criteria based on changing array

    Quote Originally Posted by JasperD View Post
    but how do I store the particulare visible cells values into an array?
    I think you have to loop through the cells to check whether the row is visible or not.

    If it is visible then you have to store it in array with the help of If routine.

    http://dailydoseofexcel.com/archives...d-list-in-vba/

  11. #11
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Set autofilter criteria based on changing array

    Me being lazy and don't wanting to loop, I took the following approach:

    Please Login or Register  to view this content.
    This perfectly well puts all the cells that I need into an array.
    And
    Please Login or Register  to view this content.
    Sets the filter as expected.

    Awesome, thanks for your help, guys!

+ 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. AutoFilter Get Criteria Array
    By alexbeatle in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-13-2014, 09:45 AM
  2. Autofilter Array Criteria
    By weeeee0713 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-16-2014, 03:45 AM
  3. Using an array as criteria in an AutoFilter
    By brucemc777 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-28-2014, 10:15 AM
  4. [SOLVED] AutoFilter: Array as Criteria
    By Klaster in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-10-2014, 06:36 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