+ Reply to Thread
Results 1 to 11 of 11

VBA code for cell date is less than current date + 2months

  1. #1
    Registered User
    Join Date
    04-04-2013
    Location
    Darwin Australia
    MS-Off Ver
    Excel 2010
    Posts
    36

    VBA code for cell date is less than current date + 2months

    Hello,
    Can someone please help me with a line of code to say: "if the cell date is less than todays date +2months then..."

    I need it to to replace this line of code:


    Please Login or Register  to view this content.
    used in this part of the code:

    Please Login or Register  to view this content.
    Thanks

    Craig

  2. #2
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: VBA code for cell date is less than current date + 2months

    Please Login or Register  to view this content.
    Elegant Simplicity............. Not Always

  3. #3
    Registered User
    Join Date
    04-04-2013
    Location
    Darwin Australia
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: VBA code for cell date is less than current date + 2months

    Hi AndyLitch
    I put the line of code into my code as below:

    Please Login or Register  to view this content.
    but it also collects dates outside "date +2 months" maybe i need to include more of your code, any suggestions?

    Thanks

    Craig

  4. #4
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: VBA code for cell date is less than current date + 2months

    Hmmm ... It's a bit weird... I tried it and it was only adding a month to mine

    Try this
    Please Login or Register  to view this content.
    and put a messagebox in it temporarily so you can see what it's checking for

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    04-04-2013
    Location
    Darwin Australia
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: VBA code for cell date is less than current date + 2months

    hi Andy,
    No good, that code doesnt seem to extract dates within the 2 month window (today +2month). I have lists of info on several sheets and the macro loops through them all to extract lines of info containing an expiry date which is less than the current date +2month. It worked well when I used code extracting dates which I had manually changed to red font, but this is very tedious and takes a long time... Any other ideas ?

    Thanks

    Craig

  6. #6
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: VBA code for cell date is less than current date + 2months

    That dateserial appears to be rubbish.... If 60 days is any good you could use

    If Sheet3.Cells(Y, 2).Value < Int(Now()) + 60 Then

    as an inetrim measure and I'll look deeper into it

  7. #7
    Registered User
    Join Date
    04-04-2013
    Location
    Darwin Australia
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: VBA code for cell date is less than current date + 2months

    Andy
    I Just tried

    Please Login or Register  to view this content.
    it appears to work, ill do some double checking let you know


    Thanks

  8. #8
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: VBA code for cell date is less than current date + 2months

    Try this :
    Please Login or Register  to view this content.
    Worked for me, but my EXCEL date formatting is different than yours, so let me know if it works, please :-)

  9. #9
    Registered User
    Join Date
    04-04-2013
    Location
    Darwin Australia
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: VBA code for cell date is less than current date + 2months

    Hi Andy

    Yes, it is working, thanks for the guidance

    Regards

    Craig

  10. #10
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: VBA code for cell date is less than current date + 2months

    Hi Craigten : Andy's solution is "Today + 60 days", while mine is "Today + 2 months" ; this of course differs - perhaps try both solutions?

  11. #11
    Registered User
    Join Date
    04-04-2013
    Location
    Darwin Australia
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: VBA code for cell date is less than current date + 2months

    Sorry Jasper, wasnt aware you had joined in, I tried your code but it doesnt work (run time error), ill stick with the simple code in post #7, seems to work ok, ill do some testing with it.. 60 days / 2months its just a warning period for me to act so +/- a few days doesnt really matter too much.
    Not sure why yours didnt work with my code, code in post #7 seems easier unless it gives me an error later on, hope not, but at least i have something now to work with..

    Thanks guys

    Craig
    Last edited by craigten; 05-07-2013 at 09:27 AM. Reason: additional iwording

+ 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