+ Reply to Thread
Results 1 to 6 of 6

Check to ensure that two dates are within one year

  1. #1
    Registered User
    Join Date
    10-12-2011
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    3

    Check to ensure that two dates are within one year

    Hello All

    Very new in VBA so please do excuse if i sound illogical, i am building a excel sheet which has inputs in form of dates in two cell i have used a date picker for that.
    After getting the dates in the cells i need to check if the start and the end date should not exceed one year.

    In case it does then it should pop a message stating that it has exceeded a year and then wipe out the two dates if they are within a year they should remain as is.

    Looking for all the help and thanks in Advance

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Check to ensure that two dates are within one year

    Laid out in simple code for you

    Please Login or Register  to view this content.

  3. #3
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: Check to ensure that two dates are within one year

    Hi ajil,
    Welcome to the Forum.
    You may also try a worksheet change event code to achieve this. Place the code given below on the worksheet module.
    Please Login or Register  to view this content.
    Please find the attached and follow the instructions on the sheet.
    Attached Files Attached Files
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  4. #4
    Registered User
    Join Date
    10-12-2011
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Check to ensure that two dates are within one year

    Hello All

    Thanks both for the suggestions, however i think that the change event code method would be the right approach, however i am facing a problem when i insert a date picker in that, i am attaching the sheet that you send sktneer with the object inserted. also i couldn't figure how to customize the cells, the cells in my sheet are C14 and E14.

    Thanks again for all your help

    Regards
    Ajil
    Attached Files Attached Files

  5. #5
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: Check to ensure that two dates are within one year

    If C14 contains the Start Date and E14 contains the End Date, then replace the previous code with this one......
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    10-12-2011
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Check to ensure that two dates are within one year

    Hello sktneer

    Thanks for your post, i have been able to utilize the code successfully in the sheet and its working if i am inputting the dates, however in order to standardize i am trying to use a date picker module but the code does not seem to work. Could you please help further ?

  7. #7
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: Check to ensure that two dates are within one year

    I have never used worksheet change event if a target is changed with a date picker and I don't find any solution to it right now. But one possible way to achieve this is you may use Worksheet_SelectionChange Event rather than ChangeEvent. The change event will fire immediately if a target cell is changed while selection change event is fired if the selection is changed. So after picking a date from a date picker, once you hit enter or select any other cell, the code will be fired and do the same as you expect it to do. See if this is something you can work with unless you get a way to make change event code to work with date picker.
    Please Login or Register  to view this content.
    Just replace the previous code (Worksheet_Change) with the above code (Worksheet_SelectionChange) and see if this works as per your requirement.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Compare two dates, ensure chronological
    By johnandrews in forum Excel General
    Replies: 4
    Last Post: 12-11-2013, 08:25 AM
  2. [SOLVED] Check if a date is between two dates but with month/year complications
    By donkeybusiness in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-05-2012, 09:31 PM
  3. Check: Ensure all Values in a Range Are Unique
    By JungleJme in forum Excel General
    Replies: 4
    Last Post: 04-14-2010, 09:33 AM
  4. Replies: 2
    Last Post: 07-12-2009, 04:52 PM
  5. check to see if all dates are for the current year
    By Oldjay in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-26-2005, 08:45 PM

Tags for this Thread

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