+ Reply to Thread
Results 1 to 4 of 4

Convert String or Text to Date

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-11-2009
    Location
    Toronto
    MS-Off Ver
    Excel 2010
    Posts
    517

    Convert String or Text to Date

    Hi,
    I'm trying to convert 161017 to date 10/17/16 using VBA. I thought Cdate function would work but no luck. Thanks for help.

    ValueDate = Cdate(Format(Worksheets("Data").Range("A1").Value, "YY/MM/DD"))

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Convert String or Text to Date


    Hi,

    first try ValueDate = CDate(Range("Data!A1").Value)

    If it fails, so the cell text does not respect your regional date format, just see CDate VBA inner help !
    In this case, you can split text to form a valid date for CDate or DateSerial functions using Mid function (to see in VBA help) …

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Convert String or Text to Date

    Hi biznet,
    Try
    Function ToDate(Num6 As Double) As Date
        Dim NumStr As String
        NumStr = CStr(Num6)
        ToDate = DateValue(Mid(NumStr, 3, 2) & "/" & Left(NumStr, 2) & "/" & Right(NumStr, 2))
    End Function
    See attached using this function above.
    UDF to change YYMMDD number ToDate.xlsm
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Forum Contributor
    Join Date
    12-11-2009
    Location
    Toronto
    MS-Off Ver
    Excel 2010
    Posts
    517

    Re: Convert String or Text to Date

    Thanks Marvin and Marc. Both of your solutions worked

+ 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] Convert a text string to a date.
    By AZNewbie in forum Excel General
    Replies: 2
    Last Post: 06-28-2016, 05:49 PM
  2. [SOLVED] Convert text string into date
    By maacmaac in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-20-2016, 01:08 AM
  3. [SOLVED] Convert text string to date
    By maacmaac in forum Excel General
    Replies: 5
    Last Post: 11-29-2015, 08:33 PM
  4. [SOLVED] Convert a Text String Date to Date Serial Number
    By herve73 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-10-2015, 10:53 AM
  5. Convert text string to a date?
    By Aland2929 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-24-2009, 07:57 AM
  6. [SOLVED] Convert text string to date
    By AK in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-01-2006, 02:30 PM
  7. How do I convert a text string into a date?
    By JJMCDD02 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-25-2005, 08:40 AM

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