Results 1 to 5 of 5

How to set multiple criteria for .advancedfilter in VBA

Threaded View

dorian821 How to set multiple criteria... 06-01-2016, 05:01 AM
Norie Re: How to set multiple... 06-01-2016, 06:16 AM
dorian821 Re: How to set multiple... 06-01-2016, 09:01 AM
Norie Re: How to set multiple... 06-01-2016, 11:02 AM
dorian821 Re: How to set multiple... 06-02-2016, 04:48 AM
  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

    
    Sub Filter_Report()
    
    
    Dim crit1 As Single
    Dim crit1lo As Range
    Dim crit1hi As Range
    Dim crita As Range
    Dim Report As Worksheet
    Dim r As Integer
    Dim data As Worksheet
    Dim crit1rng As Range
    Dim temp As Worksheet
    
    
    Workbooks("MT_Optimizer").Sheets("AAPL_Days_1").Select
    Set data = Workbooks("MT_Optimizer").Sheets("AAPL_Days_1")
    
    
    r = data.Cells(data.Rows.Count, "A").End(xlUp).Row
    Set crita = data.Range("AY30:AY" & r)
    
    
    
    
    crit1 = data.Cells(30, 51).Value
    Set crit1lo = data.Cells(30, 51).Value - 0.05
    Set crit1hi = data.Cells(30, 51).Value + 0.05
    Set crit1rng = Union(Range("<=" & crit1hi) & Range(">=" & crit1lo))
    
    
    
    
    Worksheet.Add
    ActiveSheet.Name = temp
    
    
    crita.AdvancedFilter Action:=xlFilterCopy, criteriarange:=crit1rng, copytorange:=temp("a1"), unique:=False
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    End Sub
    Last edited by dorian821; 06-02-2016 at 04:44 AM.

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. [SOLVED] 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. 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