Date format in VBA

W

Wanna Learn

Hello I'm creating a user form in VBA. the Label is "Date received" and
this is what I have.
Me.txtDate = Format(Date, "mmm-dd-yy")
problem is that this shows the current date. What I want is for the person
to enter the date but no mattter how the date is entered to be formatted as
mmm-dd-yy thanks
 
M

Mike H

Hi,

It's a big ask to be able to allow people to enter a date in 'any' format
and expect Excel to recognise that but with a recognisable date in the text
box this gives the result you want.

Private Sub txtdate_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If txtdate = vbNullString Then Exit Sub
If IsDate(txtdate) Then
txtdate = Format(txtdate, "mmm-dd-yyyy")
Else
MsgBox "Non valid date"
Cancel = True
End If
End Sub

Mike
 
W

Wanna Learn

Thanks
This is perfect but
Can I use this calendar in a user form? Data is being entered using a user
form I created. Thanks Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top