I am trying to validate a TextBox in Userform. The user can only enter in the format of xx.x so for example 34.5 is acceptable
If the user enters something like 3.4 a msgbox is shown and the user is asked to enter again.
My problem is the msgbox is showning when the user enters the correct format (for example 45.6)
I am using the BeforeUpdate function for the TextBox. The problem must be in the below code:
Private Sub TextBox2_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean) my_format = Format("00.0") If Not my_format Then MsgBox " xx.x is the required format.", vbCritical Cancel = True End If End Sub
I think the problem is on the line: If Not my_format Then ….
What I am trying to say is If TextBox.Value is not equal to my_format show a msg