Format Text Box

k209310

Active Member
Joined
Aug 12, 2002
Messages
382
I have seen the post on formatting the text box and this got m,e thinking.

How would it be possible to force a user to enter a date as dd/mm/yyyy for example?

Ie return an error message if format is incorrect or prevent the user fom entering letter.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Juan Pablo González

MrExcel MVP
Joined
Feb 8, 2002
Messages
11,959
Use the BeforeUpdate to check what the user entered, compare it to your "standard" and if it's wrong, set the Cancel parameter to True so the user is forced to put a correct value. You can show a message by using MsgBox.
 

k209310

Active Member
Joined
Aug 12, 2002
Messages
382
Thabnks for the reply its exactly what i want.

Could someone set the cancel = True bit in a bit more detail please. Im not too sure about it.
This message was edited by k209310 on 2002-11-07 11:12
 

Juan Pablo González

MrExcel MVP
Joined
Feb 8, 2002
Messages
11,959
Something like this, where TextBox1 is the name of your TextBox.<pre>Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
If MyCondition = False Then
'User screw up
MsgBox "Hey, correct me !"
Cancel = True
End If
End Sub</pre>
 

Forum statistics

Threads
1,144,122
Messages
5,722,613
Members
422,447
Latest member
knopp

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