Format year problem

T

Todd Huttenstine

Private Sub TextBox1_Exit(ByVal Cancel As
MSForms.ReturnBoolean)
TextBox1.Value = Format(TextBox1.Value, "mm/dd/yyyy")
End Sub


The above code formats the textbox. There is a problem.
If I were to type in 03/12/04 and then exit the textbox,
the textbox shows 1405 for the year.

Why?

Todd Huttenstine
 
B

Bernie Deitrick

Todd,

Probably because Textboxes return text, not dates.

Try

TextBox1.Value = Format(CDate(TextBox1.Value), "mm/dd/yyyy")

HTH,
Bernie
MS Excel MVP
 

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