Check if textbox contains a UK date only?

RockEd

Board Regular
Joined
Aug 13, 2021
Messages
80
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have some code to check if textbox contains a date and if so, write it to the spreadsheet, as so (the top line):

VBA Code:
                If IsDate(TB_Date_of_Decs.Text) Then
                                
                ActiveSheet.Cells(.Row, Range("Date_of_Decs").Column) = CDate(TB_Date_of_Decs.Text)
            
                    Else
            
                MsgBox ("You did not enter a valid date in the date of decs field."), vbCritical + vbOKOnly
            
            
                End If

However, it allows US dates through (i.e. I only want it to accept DD/MM/YYYY; but it will also accept MM/DD/YYYY etc.).

Is there a way round this?
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
No. How would you tell the difference between 1/2/2022 meaning 1st Feb or 2nd Jan?

May I ask why it matters? Shouldn't you let the user input dates in whatever their natural format is?
 
Upvote 0
Solution
Yeah fair enough. The only people that will use this spreadsheet will be based in the UK I felt that if someone wrote say 10/15/2022 that it was more likely to be a typo (that would be missed), than purposefully wanting to write 15th October 2022 etc.

Thanks anyway!
 
Upvote 0
For something like that you could always use Split to break the entry into three parts and then check if the middle part is >12 but that's about all I can think of.
 
Upvote 0
Yeah good point, it's probably a very small chance of happening so I'll leave it. Thanks for your help though.
 
Upvote 0

Forum statistics

Threads
1,215,754
Messages
6,126,681
Members
449,328
Latest member
easperhe29

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