Consulting

Results 1 to 7 of 7

Thread: Solved: Applying an Advanced Filter Using VBA

  1. #1
    VBAX Expert
    Joined
    Feb 2010
    Posts
    696
    Location

    Solved: Applying an Advanced Filter Using VBA

    I am trying to test the following code to apply an advanced filter on an existing database of classmates. The script does nothing except select of the range of cells to be filtered. My criteria range includes "="Attending"" (without the outside quotation marks).

    [vba]
    Sub filterClassmates()
    Worksheets("MyContacts").Activate
    Range("Q3", Range("Q1000").End(xlUp)).Select
    Selection.AdvancedFilter action:=xlFilterCopy, CriteriaRange:=Range("Q1"), CopyToRange:=Worksheets("Test").Range("A3"), Unique:=True
    Worksheets("Test").Activate
    Range("A1").Select
    [/vba]
    What is preventing this filter from working properly?
    Last edited by Opv; 03-29-2010 at 11:56 AM.

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,058
    Location
    Have you tried "=" & "Attending" if this is what you are using to filter on?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    VBAX Expert
    Joined
    Feb 2010
    Posts
    696
    Location
    Quote Originally Posted by Aussiebear
    Have you tried "=" & "Attending" if this is what you are using to filter on?
    Thanks. I just tried that. No change. The script runs but nothing happens

  4. #4
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,058
    Location
    Hmmm.... what about trying the following

    Criteria:= .Range("Q1")
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  5. #5
    VBAX Expert
    Joined
    Feb 2010
    Posts
    696
    Location
    Quote Originally Posted by Aussiebear
    Hmmm.... what about trying the following

    Criteria:= .Range("Q1")
    Thanks to your suggestion, I realized one of my problems. I did not include the field name in my criteria range. Let me experiment a bit more and see if I can get things working. Will advise.

  6. #6
    VBAX Regular
    Joined
    Jul 2008
    Location
    Dallas, TX
    Posts
    9
    Location
    It sounds like you are trying to do an autofilter with the results copied to a different place.

    If you want to use an advanced filter, the entire database must be selected and the criteria range must include the list header with the criteria below that (cell q1 = name of database field, cell q2 = attending).

  7. #7
    VBAX Expert
    Joined
    Feb 2010
    Posts
    696
    Location
    I got the code working. Thanks for the help.

    Opv

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •