Format Validation of a Form Input Box

NSN_VBA

New Member
Joined
Aug 3, 2018
Messages
7
Hi,

I have created a form where I would like to validate the information entered in the input box is a specific format.

The format I am trying to confirm is that it is fixed, i.e. "[FONT=&quot]Display at least one digit to the left and two digits to the right of the decimal separator."[/FONT]

Here is what I have written, but it doesn't seem to work;

If Not Format(TargetDiameter, "Fixed") Then
Call TargetDiameterShowError("Incorrect Format!")
Cancel = True
End If

Please would you be able to help?

Thanks
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
How about
Code:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
   If Not Me.TextBox1.Value Like "*#.##" Then
      Call TargetDiameterShowError("Incorrect Format!")
      Cancel = True
   End If
End Sub
 
Upvote 0
How about just fixing the format rather than nagging the user
Code:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
   TextBox1.Text = Format(Val(TextBox1.Text), "0.00")
End Sub
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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