+ Reply to Thread
Results 1 to 5 of 5

Autofilter on multiple condition using an Array

Hybrid View

  1. #1
    Registered User
    Join Date
    12-29-2009
    Location
    North Wales
    MS-Off Ver
    Excel 2007
    Posts
    42

    Autofilter on multiple condition using an Array

    Hello

    Its pretty much in the header, I need to select multiple criteria in an autofilter, I have found the best way to do this is in an array. I can add the array but i'm struggling to add the conditions to the array within the criteria.

    here is my example:

    Dim Counter As Integer
    Dim wksht As String
    Dim Condition(4) As Variant
    
    Workbooks("KYC Downloader.xlsm").Activate
        Sheets("Front Sheet").Select
        Sheets("Front Sheet").Copy Before:=Workbooks("Raw Data.Xlsx").Sheets(1)
        Range("A2").Select
        
    Sheets("Sheet1").Activate
    Cells.EntireColumn.AutoFit
    Selection.AutoFilter
    
    For Counter = 1 To 9
    
        Worksheets.Add.Name = Counter
    
        Sheets("Front Sheet").Select
        column = ActiveCell.Offset(0, 3)
        Condition(0) = ActiveCell.Offset(0, 4)
        Condition(1) = ActiveCell.Offset(0, 5)
        Condition(2) = ActiveCell.Offset(0, 6)
        Condition(3) = ActiveCell.Offset(0, 7)
    
    wksht = Counter
    
    Sheets("Sheet1").Select
    
    Selection.AutoFilter Field:=column, Criteria1:=Condition() ' i cant get it to add all the elements into the array
    
    Cells.Select
    Selection.Copy
    Sheets(wksht).Activate
    Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats
    Cells.EntireColumn.AutoFit
    Sheets("Front Sheet").Activate
    ActiveCell.Offset(1, 0).Select
    
    Sheets("Sheet1").Select
    Selection.AutoFilter
    
    
    Next Counter
    Please can someone help me?

    Thanks
    Ricco
    Last edited by Ricco Balboa; 08-11-2010 at 08:32 AM.

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

    Re: Autofilter on multiple condition using an Array

    Your array declaration should be:
    Dim Condition(3) As Variant
    and the filter line should be:
    Selection.AutoFilter Field:=column, Criteria1:=Condition(), Operator:=xlFilterValues
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Registered User
    Join Date
    12-29-2009
    Location
    North Wales
    MS-Off Ver
    Excel 2007
    Posts
    42

    Re: Autofilter on multiple condition using an Array

    In my country we would call you a "Legend"

    Thank you very much.

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

    Re: Autofilter on multiple condition using an Array

    You're welcome.
    In my country, I get called a lot of things - that's not usually one of them.

  5. #5
    Registered User
    Join Date
    12-29-2009
    Location
    North Wales
    MS-Off Ver
    Excel 2007
    Posts
    42

    Re: Autofilter on multiple condition using an Array

    Were probably in the same one to be honest, you've saved my bacon anyway.

+ 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