Hey, I've only been using VBA for a couple of days and was wondering how to apply restrictions so that only data of a certain format can be entered into a textbox.
Specifically at the moment I am looking at making it so a textbox can only contain valid dates of the format "dd/mm/yyyy" and if this is not the case I would like a message box to come up as well as setting the focus back to that textbox.
I have tried
Specifically at the moment I am looking at making it so a textbox can only contain valid dates of the format "dd/mm/yyyy" and if this is not the case I would like a message box to come up as well as setting the focus back to that textbox.
I have tried
Code:
Private Sub Text1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Text1.Value <> Format(CDate(Text1.Value), "dd/mm/yyyy") Then
MsgBox "Must Be Format dd/mm/yyyy"
Text1.SetFocus
End If
End Sub