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

Thread: How to convert date from text format to numeric number forma

  1. #1
    New Member
    Join Date
    Apr 2002
    Location
    Michigan, USA
    Posts
    17
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi,

    I am going to convert the date from text format to numeric number format. Like this:

    08/22/1998 = 36029.

    Could you teach me how to get it using VBA?

    Thank you very much.

    ssunchen

  2. #2
    MrExcel MVP Mark O'Brien's Avatar
    Join Date
    Feb 2002
    Location
    Columbus, OH, USA
    Posts
    3,530
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Reasonably simple since VBA will take care of this conversion for you, here's an example:


    Public Sub main()

    Dim oDate As Date
    Dim iDate As Long

    oDate = "08/22/1998"
    iDate = oDate

    MsgBox iDate

    End Sub


    oDate is the literal date, iDate is the date set as a long integer value.

    HTH

  3. #3
    MrExcel MVP Jay Petrulis's Avatar
    Join Date
    Mar 2002
    Location
    Chicago, IL USA
    Posts
    2,040
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi,

    This worked for me, after selecting the range you want to change.

    Sub test()
    Dim Rng As Range

    For Each Rng In Selection

    If IsNumeric(Rng) Then
    Rng.NumberFormat = "General"
    Else
    On Error Resume Next
    Rng = DateValue(Rng)
    On Error GoTo 0
    Rng.NumberFormat = "General"
    End If
    Next Rng
    End Sub


    Bye,
    Jay

  4. #4
    New Member
    Join Date
    Feb 2012
    Posts
    4
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: How to convert date from text format to numeric number forma

    thanks... simple yet works great! you are the man!

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
  •