Thank you Rick.you have given me right solution
Rick Rothstein (MVP -
VB) wrote:
Add this function to your UserForm's code window (it will return True if the
String value passed into it is an integer or properly formed floating point
value)...
Function IsNumber(ByVal Value As String) As Boolean
' Leave the next statement out if you don't
' want to provide for plus/minus signs
If Value Like "[+-]*" Then Value = Mid$(Value, 2)
IsNumber = Not Value Like "*[!0-9.]*" And _
Not Value Like "*.*.*" And _
Len(Value) 0 And Value < "." And _
Value < vbNullString
End Function
and then use this code for the TextBox's Exit procedure..
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
With TextBox1
If Len(.Text) 0 And Not IsNumber(.Text) Then
MsgBox "Invalid entry! Please try again."
Cancel = True
.SelStart = 0
.SelLength = Len(.Text)
End If
End With
End Sub
Of course, change the example TextBox1 name I used for the TextBox to the
actual name of your TextBox.
Rick
How to codify the following logic:
A textbox in a userform can be left blank without entering any
[quoted text clipped - 11 lines]
or
corrects the entry by putting only numeric values.
--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200806/1