+ Reply to Thread
Results 1 to 4 of 4

use variable in macro for date

  1. #1
    Registered User
    Join Date
    09-16-2010
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    50

    use variable in macro for date

    Hi, I have a macro that I must change about 10 dates in as it autofilters by date in certain columns like this..

    Selection.AutoFilter Field:=7, Criteria1:=">10/15/2010", Operator:=xlAnd, _
    Criteria2:="<10/22/2010"


    Is there a way to make criteria 1 use todays date, and criteria 2 use todays date + 7 days ?
    do i need to use a variable for the system date ?
    Last edited by vsantoro; 10-26-2010 at 09:41 AM.

  2. #2
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161

    Re: use variable in macro for date

    Not tested:

    Like this:
    Please Login or Register  to view this content.
    Microsoft Office Help - Excel VBA Programming
    Not all forums are the same - seek and you shall find

  3. #3
    Registered User
    Join Date
    09-16-2010
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    50

    Re: use variable in macro for date

    Thanks, Excel knows +7 means plus 7 days ? not 7 years, or 7 months ?

  4. #4
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161

    Re: use variable in macro for date

    Quote Originally Posted by vsantoro View Post
    Thanks, Excel knows +7 means plus 7 days ? not 7 years, or 7 months ?
    Yes, Excel works in days,
    7 days = 1 week
    365 days = 1 year....etc

    You may have to do this with the greater/less than signs:
    Criteria:=">" & Date...etc

+ 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