date format problem

brianfosterblack

Active Member
Joined
Nov 1, 2011
Messages
251
I am using this code in a macro. The result from the code gives me the date mm/DD/yyyy although my computer is set to the English format of dd/MM/yyyy
Can you please advise what I have done wrong?
VBA Code:
    Application.ScreenUpdating = False
    ActiveSheet.Unprotect
    Range("AC2000").Select
    Selection.End(xlUp).Select
    ActiveCell.Offset(1, 0).Select
    ActiveCell.Value = InputBox("Enter Date in this format - dd/MM/yyyy")
    If Not IsDate(ActiveCell.Value) Then
    Application.ScreenUpdating = True
    ActiveSheet.Protect
    MsgBox ("You have not entered a valid date in the Start Date. " & vcCr & _
    "Please correct this")
    ActiveCell.Value = ""
    Exit Sub
    End If
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
39,292
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
InputBox returns a string, which will be interpreted in VBA's default US settings unless you tell it otherwise. You can use:

Code:
ActiveCell.Value = CDate(InputBox("Enter Date in this format - dd/MM/yyyy"))

but you'll need an error handler in case they enter something invalid.
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
65,427
Office Version
  1. 365
Platform
  1. Windows
One thing that you can do to help eliminate data entry errors is to use a Calendar Date Picker instead of relying on the user to manually enter the date correctly.

There are a few different ways you can do that. Here are a few options (there are others, if you do a Google search on "Excel Calendar Date Picker"):
 

brianfosterblack

Active Member
Joined
Nov 1, 2011
Messages
251
One thing that you can do to help eliminate data entry errors is to use a Calendar Date Picker instead of relying on the user to manually enter the date correctly.

There are a few different ways you can do that. Here are a few options (there are others, if you do a Google search on "Excel Calendar Date Picker"):
Thanks for this Joe4. I am saving the links and will study up on it tomorrow. Sounds like a much better idea.
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
65,427
Office Version
  1. 365
Platform
  1. Windows
You are welcome.
Glad we were able to help!
 

Forum statistics

Threads
1,175,457
Messages
5,897,531
Members
434,660
Latest member
Stoyf

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
Top