+ Reply to Thread
Results 1 to 6 of 6

Selecting more than two items in an AutoFilter

Hybrid View

  1. #1
    Forum Contributor tangcla's Avatar
    Join Date
    06-04-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2010
    Posts
    136

    Selecting more than two items in an AutoFilter

    OK, please interrupt me where I can improve on processes.
    As part of my macro, I need to select ten items in my table of data to import into another worksheet.

    Is there a way to select more than two if I edit the macro code itself? I tried but it didn't seem to work, by extending the line to include further Criterion:

    Selection.AutoFilter Field:=2, Criteria1:="=Fuel Sales", Operator:=xlOr, Criteria2:="=C-Store Sales"

  2. #2
    Forum Contributor tangcla's Avatar
    Join Date
    06-04-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2010
    Posts
    136
    OK, here's a sample file.

    basically, say I want to automate a copy-paste of only "Fuel Sales", "C-Store Sales", "car Wash Sales/GP", "SALES", "GROSS PROFIT" - how would you do it?
    I'll need to macro-ize it, too.


    My two thoughts:
    a) Learn how to do a filter function which can do more than two variables
    b) Learn how to specify relative cell references in rows (i.e. "down one row")
    Attached Files Attached Files

  3. #3
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Use the advanced filter. With your example file run the following code.

    Sub aaa()
      Dim OutSH As Worksheet, DataSH As Worksheet
      Set OutSH = Sheets("Sheet2")
      Set DataSH = Sheets("Sheet1")
      OutSH.Range("A1:C1").Value = DataSH.Range("A1:C1").Value
      OutSH.Range("E1").Value = DataSH.Range("B1").Value
      OutSH.Range("E2:E6").Value = WorksheetFunction.Transpose(Array("Fuel Sales", "C-Store Sales", "car Wash Sales/GP", "SALES", "GROSS PROFIT"))
      DataSH.Range("A1").CurrentRegion.AdvancedFilter action:=xlFilterCopy, copytorange:=OutSH.Range("A1:C1"), criteriarange:=OutSH.Range("E1:E6")
      
    End Sub
    rylo

  4. #4
    Forum Contributor tangcla's Avatar
    Join Date
    06-04-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2010
    Posts
    136
    At the risk of looking noob... how does one use this code you have provided?

    Tried using it as a macro and it didn't do anything...
    Last edited by tangcla; 06-19-2008 at 12:50 AM.

  5. #5
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Open your example file, ALT F11, Insert, Module, paste the code, run the code, then view the output on sheet2.


    rylo

  6. #6
    Forum Contributor tangcla's Avatar
    Join Date
    06-04-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2010
    Posts
    136
    Ohhhh didn't realise it output the files into Sheet2!

    Now I gotta see if I can butcher this code into a macro of sorts...

    Thanks again, you're my hero rylo

+ 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