Date Fomat and VBA

k209310

Active Member
Joined
Aug 12, 2002
Messages
382
Is ther any way to automatically insert a carachter when user enters certain info in to a text box. ie for a date a user could enter 12 and then a / would automatically appear.

This would save the user having to worry about the date format.

Im not too sure if this can be done in VBA. I have seen it done in javascript.
 

Some videos you may like

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
This works, but the user must enter a leading zero if the day or month is less than 10.

Code:
Private Sub TextBox1_Change()
    If Len(TextBox1.Text) = 2 Then
        TextBox1.Text = TextBox1.Text & "/"
    ElseIf Len(TextBox1.Text) = 5 Then
        TextBox1.Text = TextBox1.Text & "/"
    End If
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,127,222
Messages
5,623,470
Members
415,973
Latest member
johnemaile

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
Top