Consulting

Results 1 to 4 of 4

Thread: Using a variable to as criteria in autofilter

  1. #1
    VBAX Newbie
    Joined
    Apr 2013
    Posts
    2
    Location

    Using a variable to as criteria in autofilter

    Hi, hope someone out there can help.
    I am trying to run the code below but keep getting a runtime error code 1004 - Application-defined or object-defined error.

    ActiveSheet.Range("$A$:$Q").AutoFilter Field:=15, Criteria1:= _
    MyCell, Operator:=xlFilterValues

    I declared MyCell as a Range and want to use it as a filter criteria in my data A$:Q$.

    Any help will be much appreciated.

  2. #2
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    [vba]
    with ActiveSheet.usedrange.resize(,17)
    .AutoFilter 15, MyCell.value
    end with
    [/vba]

  3. #3
    VBAX Newbie
    Joined
    Apr 2013
    Posts
    2
    Location
    Works perfect.

    Many thanks snb, made my day!

  4. #4
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    Too much honour, your Honour.

Posting Permissions

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