1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

EXCEL: Custom Filter Macro

Discussion in 'Business Applications' started by ljzmcm, Sep 22, 2008.

Thread Status:
Not open for further replies.
  1. ljzmcm

    ljzmcm Thread Starter

    Joined:
    Apr 28, 2008
    Messages:
    148
    Hey all,

    I have a custom filter that does:

    Greater than or equal too: (date here)

    AND

    Less than or equal too: (another date)

    I recorded the macro, but I want to put the two dates from a cell

    this is all wrong, but maybe you can see where I'm going with this:

    Sub CustomFilter()
    '
    ' CustomFilter Macro
    '
    ' Keyboard Shortcut: Ctrl+j
    '
    Selection.AutoFilter Field:=4, Criteria1:=">=(Range("H3").Value)", Operator:=xlAnd _
    , Criteria2:="<=(Range("J3").Value)"
    End Sub

    Should be simple... Any help, please?
     
  2. bomb #21

    bomb #21

    Joined:
    Jul 1, 2005
    Messages:
    8,546
    First thing, your syntax is off.

    Selection.AutoFilter Field:=4, Criteria1:=">=" & Range("H3"), _
    Operator:=xlAnd, Criteria2:="<=" & Range("J3")


    That works for me if Field4 (column D?) and H3/J3 are plain numbers.

    Of course, in Excel dates are plain numbers. So possibly the second thing is are you outside the US. Manipulating dates in VBA can be troublesome because Excel tends to think dates in US format.

    Where are you going with this? Presumably a macro to filter by dates can't be all you're aiming for.
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/752353

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice