Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 5 of 5

Thread: Date Format

  1. #1
    Board Regular
    Join Date
    Feb 2002
    Posts
    145
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    When reading in a date value from a cell with the format of mm/dd/yy, how do I convert this to the integer value in code. For example: read in 02/25/02 and have my variable show 37312. I know it's not tough, I just can't seem to find any of my old snippets with the Format code.

    As always, thank you for your help.

  2. #2
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Sydney, Australia
    Posts
    2,940
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default

    Here's one way:-

    MsgBox CLng(Range("A1").Value)

    Regards,
    D

  3. #3
    Board Regular
    Join Date
    Feb 2002
    Posts
    145
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    The date is pre-determined in a closed workbook, I don't need the user screwing it up (if you know what I mean!). I know there is a way through code to format, I just can't find it. Needs to be through code!

  4. #4
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Sydney, Australia
    Posts
    2,940
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default

    That is code.

    Sub GetNumericDate()
    Dim lngDateVal As Long

    lngDateVal = CLng(Range("A1"))

    End Sub

    Regards,
    D

  5. #5
    Board Regular
    Join Date
    Feb 2002
    Posts
    145
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Crap. I'm sorry DK, I totally read that wrong. I thought you had InputBox there, my bad, that format worked great. Thank you.

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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