+ Reply to Thread
Results 1 to 3 of 3

Force date validation in specified format

  1. #1
    Registered User
    Join Date
    02-15-2016
    Location
    Indonesia
    MS-Off Ver
    2010
    Posts
    2

    Force date validation in specified format

    Hi,

    I need to validate date entry inside cells itself with format dd\mm\yyyy.
    This needed as this Excel are used to import data to other system which is accepting only dd\mm\yyyy
    For example:
    31/12/2015 -> correct
    12/31/2015 -> incorrect
    31/11/2015 -> incorrect (no 31 in November)
    other than date -> incorrect

    Have tried some solutions on internet but none working, especially when the input is 12/31/2015.
    1. Data Validation
    Cannot use this approach as user might copy and paste from other source and this will remove the validation.
    I also cannot restrict copy & paste as they need to copy and paste the data.

    2. IsDate and DateValue
    This will not work if the input is 31/11/16 or 12/31/2015
    as I read on internet, the function was not specific to date format, but it will give the combination of format.

    Been trying search this on google for a day but none of them can accommodate the issue.
    Appreciate if anyone can help or giving idea how this should be done.
    I'm using Office 2010 and the user uses Office 2013.

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: Force date validation in specified format

    The attached uses a VBA code Change event on Sheet1. The cells to be validated are in the range A2:A4. You would have to change this range to reflect where you need validation.

    I make the following checks: There are two and only two slashes in the date. The month cannot be greater than 12, the year cannot be less than 4 digits (so format the date type accordingly - months and days can be single digit), illegal dates such as 31/11/2015 won't work.

    The code warns the user, clears the contents of the cell, and selects the cell again.

    There is no way to check that 1/5/2015 is May 1st instead of January 5th.
    Attached Files Attached Files
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Registered User
    Join Date
    02-15-2016
    Location
    Indonesia
    MS-Off Ver
    2010
    Posts
    2

    Re: Force date validation in specified format

    Works like a charm!
    Thank you so much, dflak.
    So now, I will need to modify your code a bit to get what I need.

+ 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. Force Cell format as General when entering in a date.
    By Miskondukt in forum Excel General
    Replies: 2
    Last Post: 12-03-2015, 03:46 PM
  2. [SOLVED] force format date
    By pannam in forum Excel General
    Replies: 7
    Last Post: 10-20-2014, 03:44 AM
  3. [SOLVED] Trying to force a date format 'd-mmm-yy', not working.
    By tv69 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-20-2013, 03:47 PM
  4. Date Format Validation
    By steve_koz in forum Excel General
    Replies: 0
    Last Post: 06-11-2012, 10:24 AM
  5. Validation Date format
    By amitjagtap in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-24-2012, 03:25 AM
  6. Force macro to a date format. Used a userform instead
    By Philb1 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-16-2011, 05:30 AM
  7. Force cell date format
    By Macdave_19 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-20-2007, 04:07 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