Input Box Changing Date Format

stucamps

Board Regular
Joined
Jul 3, 2003
Messages
114
I have searched on the forums and tried different solutions to this common problem but to no avail.

Basically I have an input box where the user enters a date in the format "dd/mm/yyyy" and this is being returned as "mm/dd/yyyy" :oops:

I have checked my regional settings via the Control Panel and have reformatted the excel cell to "dd/mm/yyyy" both in VBA and also manually in Excel - Format>Cells>etc.

The Code I have for the InputBox is below and the formatting also
(I have included two versions of the InputBox but both still throw up the wrong date format)


Month = ThisWorkbook.Sheets(1).Range("$G$7").Value
Dim d
d = Format(InputBox("Please Enter the Inception Date for the new Share Class series you have added", "Date Entry", Format(Month, "dd/mm/yy")), "dd/mm/yyyy")
ActiveSheet.Range("A65536").End(xlUp).Offset(-14, 0).Value = Format(d, "dd/mm/yyyy")

or alternatively used this InputBox suggestion:

d = CDate(InputBox("Please Enter the Inception Date for the new Share Class series you have added", "Date Entry", Format(Month, "dd/mm/yy")))

I am trying to enter the date 1st May 2005 - as 01/05/2005 - but it is being returned as 05/01/2005.

Can someone please point out something I am missing here!

Thanks,
Stuart
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
have you tried formating the cell on the sheet where the date from the inputbox? I had the same problem with textboxes in a userform.
the date has to entered as mm/dd/yy, but the cell it's going to can have dd/mm/yy format
 
Upvote 0
Yep, I had tried that as well and it still keeps the value as before so through VBA I create the date 01/05/2005 (1st May 2005) - VBA converts this to 05/01/2005 (5th January 2005) so when I format it "manually" through Excel it still thinks that the correct date I want is 5th Jan. - I can manually take it back to 1st May but this isnt what I want to do as VBA is to run this automatically.
Thanks
Stuart
 
Upvote 0
VBA is notoriously flaky with UK dates. This worked for me:

Code:
Sub Test()
    Dim Month
    Dim d
    Month = ThisWorkbook.Sheets(1).Range("$G$7").Value
    d = Format(InputBox("Please Enter the Inception Date for the new Share Class series you have added", "Date Entry", Format(Month, "dd/mm/yy")), "dd/mm/yyyy")
    With ActiveSheet.Range("A65536").End(xlUp).Offset(-14, 0)
        .Value = CLng(DateValue(d))
        .NumberFormat = "dd/mm/yyyy"
    End With
End Sub
 
Upvote 0
Thanks alot Andrew - again you have solved my problem. You my friend are a true gent and a scholar
Stuart
 
Upvote 0

Forum statistics

Threads
1,215,981
Messages
6,128,094
Members
449,419
Latest member
mammothzaa

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top