In my excel sheet 'Booking' when a user enters a value in A8 and A10, I want it to be a…
- User
In my excel sheet 'Booking' when a user enters a value in A8 and A10, I want it to be a date value and in the following formats only dd/mm/yyyy or d/m/yy or dd/mm/yy. How can I do it
- Assistant
To ensure that users can only enter dates in the specified formats (dd/mm/yyyy, d/m/yy, or dd/mm/yy) for cells A8 and A10 in your Excel sheet 'Booking', you can use with a custom formula. Here's how you can set this up:
- User
This formula is rejecting all my date entries: =OR(AND(ISNUMBER(A8), A8=TEXT(A8, “dd/mm/yyyy”)), AND(ISNUMBER(A8), A8=TEXT(A8, “d/m/yy”)), AND(ISNUMBER(A8), A8=TEXT(A8, “dd/mm/yy”)))
- Assistant
- User
The following VBA is still rejecting my date entry even if I enter the date in the correct format
Dim dateValue As Date Dim validDate As Boolean
If Not Intersect(Target, Me.Range(“A8”)) Is Nothing Then ’ Check if the date is in the specified formats If Not (Format(dateValue, “dd/mm/yyyy”) = Target.Value Or _ Format(dateValue, “d/m/yy”) = Target.Value Or _ Format(dateValue, “dd/mm/yy”) = Target.Value) Then MsgBox “Please enter a date in the format dd/mm/yyyy, d/m/yy, or dd/mm/yy.” Application.EnableEvents = False Target.ClearContents Application.EnableEvents = True Exit Sub End If - Assistant
- User
Error: Expected array, on the line 'dateValue = dateValue(inputValue)'
- Assistant
I apologize for the oversight. The error arises from a typo in the code. The correct method to convert a string to a date is , not .
- User
When I change the 'D' in dateValue = DateValue(inputValue), excel immediately chnges it to 'd'
- Assistant