Share via

Excel does NOT recognize my Date Format

Anonymous
2014-03-31T21:03:35+00:00

I am having an issue with dates in Excel 2010. I am copying information from another program into my Excel Spreadsheet. The other program uses a date format of DDMMYY. So July 1, 2014 looks like 010714. Is there any way I can change the way that Excel "looks" at the date?

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

  1. Anonymous
    2014-04-01T03:30:18+00:00

    I was hoping that there would be a way to 'convert' Excel to adopt this? Even if it was on a sheet by sheet basis....

    Thank you for your assistance thus far.

    -Jeremy

    Well, if you're open to using a Visual Basic solution, you can set it up so that whenever one of your users enters a date in the DDMMYY format in specific cells, then a VBA routine is initiated that will automatically convert the cell contents to an actual date, or to a text string in the form "DD-MM-YY".

    There is no way to get Excel to store an input value of "010577" as a date - Excel uses its own internal format for dates, and it would look more like 28130.

    The code below can be inserted into each worksheet's code module which you get to by right-clicking on the worksheet tab and selecting "View Code".  Any time the user makes a change on the worksheet, this code will see if it changed anything in Column J (where your hand input dates are).  It checks for illegal changes, and then converts whatever was input into a text string in the "DD-MM-YY" format.

    Stick it into one of your worksheets, and try some entries into Column J to see if it works correctly.  Is this something you want to try?

    '===== BEGIN CODE =====

    Option Explicit

    Private Sub Worksheet_Change(ByVal Target As Range)

        Dim dateRange As Range, intRange As Range

        Dim theCell As Range

        Dim disAllow As Boolean

        Dim myDate As Date

    ' Set up a "range of interest" to check for incoming dates

        Set dateRange = Me.Range("J2:J50000")

    ' See if the changed cells on the worksheet intersect our range of interest

        Set intRange = Intersect(dateRange, Target)

    ' Some of our cells changed...

        If (Not intRange Is Nothing) Then

    '

    ' Before we do anything, check for disallowed changes.

    ' If we find any disallowed changes, Undo the action.

    ' Erasing cell contents is allowed.

    ' Putting values in that cannot be converted to

    ' a date is not allowed - this will result in an Undo.

    '

            disAllow = False

            For Each theCell In intRange.Cells

                If (theCell <> "") Then

                    If (Not IsLawsonDate(theCell.Value)) Then ' If we find one cell input incorrectly, undo the whole action

                        MsgBox "That change is not allowed because it produces a bad date in one or more cells!", vbExclamation + vbOKOnly, "Error!"

                        Application.EnableEvents = False

                        Application.Undo

                        Application.EnableEvents = True

                        Exit Sub

                    End If

                End If

            Next theCell

    '

    ' If we got here, the user action was legal, so just go ahead and convert the date(s).

    '

            For Each theCell In intRange.Cells

                If (theCell <> "") Then

                    Call ConvertLawsonDate(theCell.Text, myDate)

                    Application.EnableEvents = False

                    theCell = Format(myDate, "DD-MM-YY")

                    Application.EnableEvents = True

                End If

            Next theCell

        End If

    End Sub

    Private Function IsLawsonDate(ByVal inputString As String) As Boolean

        Dim i1 As Integer, i2 As Integer, i3 As Integer

        Dim returndate As Date

    '

    ' Lawson date format = "DDMMYY"

    '

        IsLawsonDate = True

    Debug.Print "hi"

        If (Len(inputString) = 5) Then inputString = "0" & inputString

        If (Len(inputString) <> 6 Or Not IsNumeric(inputString)) Then

            IsLawsonDate = False

        Else

            i1 = Left(inputString, 2)

            i2 = Mid(inputString, 3, 2)

            i3 = Right(inputString, 2)

            If (i1 < 1 Or i1 > 31 Or _

                i2 < 1 Or i2 > 12 Or _

                i3 < 1) Then IsLawsonDate = False

            On Error GoTo NotLawsonDate

            returndate = DateSerial(i3, i2, i1)

        End If

        Exit Function

    '

    NotLawsonDate:

        IsLawsonDate = False

    End Function

    Private Sub ConvertLawsonDate(ByVal inputString As String, ByRef returndate As Date)

        Dim i1 As Integer, i2 As Integer, i3 As Integer

    '

    ' Lawson date format = "DDMMYY"

    '

        If (Len(inputString) = 5) Then inputString = "0" & inputString

        i1 = Left(inputString, 2)

        i2 = Mid(inputString, 3, 2)

        i3 = Right(inputString, 2)

        On Error GoTo NotLawsonDate

        returndate = DateSerial(i3, i2, i1)

        Exit Sub

    '

    NotLawsonDate:

        returndate = DateSerial(1900, 1, 1)

    End Sub

    '===== END CODE =====

    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Ashish Mathur 101.8K Reputation points Volunteer Moderator
    2014-03-31T23:05:27+00:00

    Hi,

    Try this on a copy of the column first.

    Try using Data > Text to columns > Delimited > Next > Next > Data > DMY > Finish

    If DMY does not work, then try MDY.

    Hope this helps.

    4 people found this answer helpful.
    0 comments No comments
  2. Anonymous
    2014-03-31T23:26:41+00:00

    I was able to use this formula. The problem is, because Lawson (our program) uses said date format, we have all become accustomed to entering dates in this way.

    The columns in the left hand red box of the screenshot are the ones that are "Copy & Paste". While the columns in the right hand red box are updated daily, and entered "manually". [FYI-the Date values displayed below are formatted to display the dashes. The true cell value is without.                                   eg.  "13-03-14"(displayed), "130314"(actual)]

    I was able to convert the "Pasted" ones as you suggested by inserting another column and then referencing to it. But now we have to try and learn how to enter the values in Excel one way, and remember to use the other format when using Lawson. That leaves alot of room for error, as I'm sure you are aware. I was hoping that there would be a way to 'convert' Excel to adopt this? Even if it was on a sheet by sheet basis....

    Thank you for your assistance thus far.

    -Jeremy

    0 comments No comments
  3. Anonymous
    2014-03-31T21:28:46+00:00

    If Excel is actually showing "010714" in a cell, with the leading zero, then it is treating the cell as Text.  Excel won't allow you to format text as a date.

    If you want to convert the data, you can do that using another cell.  Use a formula something like the one below to convert the text strings to dates.  Note that my formula assumes (for the 2 digit years) that anything greater than 50 is from the previous century, meaning 010714 is July 1, 2014 and 010751 is July 1, 1951.  You can change that by changing the "50" in the equation to something else.

    =IFERROR(DATE(IF(INT(RIGHT(A1,2))>50,1900+INT(RIGHT(A1,2)),2000+INT(RIGHT(A1,2))),INT(MID(A1,3,2)),INT(LEFT(A1,2))),"ERROR")

    HTH,

    Eric

    0 comments No comments