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.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
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
 
Upvote 0

Forum statistics

Threads
1,214,830
Messages
6,121,831
Members
449,051
Latest member
excelquestion515

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