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

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
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.
 
Upvote 0
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"):
 
Upvote 0
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.
 
Upvote 0
You are welcome.
Glad we were able to help!
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,849
Members
449,051
Latest member
excelquestion515

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