+ Reply to Thread
Results 1 to 2 of 2

AutoFilter Criteria, help please.

  1. #1
    Valued Forum Contributor
    Join Date
    08-04-2011
    Location
    UK
    MS-Off Ver
    Excel 2021
    Posts
    346

    AutoFilter Criteria, help please.

    This is bugging me all day.

    Macro1 below works ok, picked up all 3 criteria, "data1", "data2" and "data3".
    Macro2 will only pick up criteria 1, "data1", I just can't figured it out why? The reason for Macro2 is range"test" is a dynamic range, is it the right approach?

    If the delete the "Operator:=xlFilterValues" at the end on Marco2, the filter will pick up the criteria one at a time and ended up with criteria3 that isn't what I wanted!

    Any comments would be much appreciated.

    Sub Macro1()
    Dim pick(1 To 3)
    pick(1) = "data1"
    pick(2) = "data2"
    pick(3) = "data3"
    ActiveSheet.Range("$A$10:$IV$5753").AutoFilter Field:=2, Criteria1:=pick, Operator:=xlFilterValues
    End Sub

    Sub Macro2()
    Dim pick
    pick = Range("test")
    ActiveSheet.Range("$A$10:$IV$5753").AutoFilter Field:=2, Criteria1:=pick, Operator:=xlFilterValues
    End Sub

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: AutoFilter Criteria, help please.

    Hi AlanY
    I may (or may not) have an answer to your issue but you first must add code tags to your code (see Forum Rule #3).
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

+ 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