Consulting

Results 1 to 4 of 4

Thread: Sleeper: Validate a Date!??

  1. #1

    Sleeper: Validate a Date!??

    Hey VBA-crackers,

    I need some help!

    I need to check if a certain cell (or range) has valid date value, how do i do it?
    To elaborate further, i make my column, say column B, as format = date. The user is free to input anything in this column -- he may even copy some data from other column onto it, thus, erasing the date format. Now, i click validate button to check if this column B values are valid date values.

    Tried with IsDate function, but wrong results.

    Anyone please help me out with this .....

    Thanks a ton!

    Regards.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Zuid-Holland
    Tried with IsDate function, but wrong results.
    What wrong results do you mean?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    The IsDate function will return a boolean result, either True or False. When are you wanting to do this? At user input? You can protect a sheet so a user cannot change a value or formula. Dates are somewhat quirky in Excel though. This is because they are recognized as (serial) numbers. So it makes for somewhat of a challenge when differentiating between dates and a number.

    If attempting this with standard worksheet functions, it's impossible. But if you want to use a UDF (User-Defined Function) this will work for you: http://www.vbaexpress.com/kb/getarticle.php?kb_id=323

  4. #4
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Hi Zuid-Holland,

    How about using the inbuilt data validation tool? (Data -> Validation) If you select 'Date' you get many options and also a start and end date.

    HTH,
    John
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •