+ Reply to Thread
Results 1 to 5 of 5

How to set multiple criteria for .advancedfilter in VBA

  1. #1
    Registered User
    Join Date
    11-19-2014
    Location
    Athens
    MS-Off Ver
    2013
    Posts
    4

    How to set multiple criteria for .advancedfilter in VBA

    Hello All,

    I am trying to use the xlfiltercopy action with the .advancedfilter function in vba to filter through some data and copy it to another sheet. The criteria for the filter, however, will be all values between two variable values that will change on every iteration of the filter, i.e a 'continuous' data set so printing all the criteria onto a range is not possible. Consequently, as the .advancedfilter function doesn't seem to allow for criteria1, criteria2, etc.. like .autofilter, I need a way to set the criteriarange to a 'between' function, i.e. x
    The code I have so far is below.

    Thanks!

    Dorian

    Please Login or Register  to view this content.
    Last edited by dorian821; 06-02-2016 at 04:44 AM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How to set multiple criteria for .advancedfilter in VBA

    Dorian

    It is possible to set a 'between' criteria for advanced filter in a range.

    In the range you would repeat the field twice in the header row and below you would have your ">=" & crit1lo and "<=" & crit1hi.

    Try doing it manually to see what I mean.

    PS Can you add code tags when posting code?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    11-19-2014
    Location
    Athens
    MS-Off Ver
    2013
    Posts
    4

    Re: How to set multiple criteria for .advancedfilter in VBA

    Thanks, What do you mean repeat the field twice in the header row?

    I've tried what I think you are suggesting, and am receiving the following error at the line for the advanced filter


    Method 'range' of object '_Global' failed

    Please Login or Register  to view this content.
    Last edited by dorian821; 06-01-2016 at 09:12 AM. Reason: to add tags

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How to set multiple criteria for .advancedfilter in VBA

    The criteria range needs to be on a worksheet, you can't 'create' it in the code.

    You can however populate the criteria range using code.

  5. #5
    Registered User
    Join Date
    11-19-2014
    Location
    Athens
    MS-Off Ver
    2013
    Posts
    4

    Re: How to set multiple criteria for .advancedfilter in VBA

    Thanks. How can I populate a range with a 'continuous' number set. In other words, I need to filter all value between, let's say, 50 & 75, where the elements have up to 4 decimal points. That is a lot of numbers to put into a range, especially when a new range needs to be defined and populated for every iteration of over 100,000 iterations. There isn't a way to define the limits of the set as with the 'between' function on excel?

+ 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] Advancedfilter with multiple criteria?
    By brucemc777 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-06-2014, 03:34 PM
  2. [SOLVED] VBA AdvancedFilter Three Criteria
    By goss in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-17-2014, 08:17 AM
  3. excel 2010 vba - advancedfilter returning ALL rows, not just criteria ones?
    By wyattea in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-12-2013, 02:36 AM
  4. Loop with AdvancedFilter Using Multiple Sheets
    By freybe06 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-14-2012, 01:10 PM
  5. AdvancedFilter with no criteria
    By opopanax666 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-26-2007, 08:35 AM
  6. Setting a criteria in an AdvancedFilter macro
    By Wendell A. Clark in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-11-2006, 11:20 AM
  7. Advancedfilter
    By ram in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-29-2005, 10:20 PM
  8. [SOLVED] Advancedfilter copy in place doesn't use criteria range correctly
    By Josh in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-09-2005, 10:35 AM

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