date format from input box

Posted on 2011-10-25
Last Modified: 2012-05-12
daterange = InputBox("Input date range", "Input DateRange")
    Range("T1").Value = daterange

I want the input to be of the format dd/mm/yyyy and the output to be dd/mm/yyyy

At the moment the output is mm/dd/yyyy.  

How do I do this please?
Question by:robinbernett
    LVL 8

    Assisted Solution

    Sub x()
       newdate = Format(Range("T1").Value, "dd/mm/yyyy")
    End Sub
    LVL 13

    Assisted Solution

    Use the Format function.

    Range("T1").Value = Format(daterange, "dd/mm/yyyy")

    LVL 80

    Accepted Solution

    VBA is always expecting US format dates: mm/dd/yyyy. It can produce dd/mm/yyyy as a string using Format function--or the recipient cell can format the date using its built-in formatting (better alternative). The following macro is tolerant of leading zeros (or not) as well as use of two digits for the year.

    Sub Dater()
    Dim sDate As String
    Dim dat As Double
    Dim i As Long, j As Long, k As Long
    For i = 1 To 3
        sDate = InputBox("Input date as dd/mm/yyyy", "Input DateRange")
        On Error Resume Next
        j = InStr(1, sDate, "/")
        k = InStr(j + 1, sDate, "/")
        dat = DateSerial(Mid(sDate, k + 1), Mid(sDate, j + 1, k - j - 1), Left(sDate, j - 1))
        On Error GoTo 0
        If dat <> 0 Then
            With Range("T1")
                .NumberFormat = "dd/mm/yyyy"
                .Value = dat
            End With
            Exit For
            MsgBox "There was an error in the date entry. Please try again."
        End If
    End Sub

    Open in new window


    Author Comment

    Thank you all.

    I much appreciate the additional understanding and learning, byundt.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    I've recently been in need of an Excel macro that could add a letter before the text on multiple cells in an Excel document. My English is as it is, so I will try explain what it does diffrently. If you have an excel document with 2000 rows an…
    Sometimes we don't want to show zeros in our Excel spreadsheets. This is sometimes most evident in our charts. Look at the chart below, all the zero values are visible. I think that all will agree with the fact that zero values are not looking nice …
    The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
    This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    26 Experts available now in Live!

    Get 1:1 Help Now