Data Validation

Mkammari

Board Regular
Joined
Nov 23, 2005
Messages
65
I am trying to force the a user to enter only numeric entries, however the entry can be left blank as well. So far this is what I have.

Code:
Private Sub txtqty15_exit(ByVal cancel As MSForms.ReturnBoolean)
If Not IsNumeric(txtqty15.Value) Then
MsgBox "You must enter a numeric value for the qty field"
With txtqty15
.SetFocus
.SelStart = 0
.SelLength = 1000
End With
End If
End Sub


yet...when the entry is left blank, I don't want the message to pop up.  I would like to accept null values as well as only numeric.  Anyone?
 

Some videos you may like

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

daniels012

Well-known Member
Joined
Jan 13, 2005
Messages
5,219
In the menu Bar!

File, Edit, View, Insert, Format, Tools, Data

Michael
 

Mkammari

Board Regular
Joined
Nov 23, 2005
Messages
65

ADVERTISEMENT

I have it in an excel worksheet, but I do not have that menu option in VBA. I am validating user input on a userform, not in an excel worksheet.
 

Oaktree

MrExcel MVP
Joined
Jun 20, 2002
Messages
7,988
Untested, but could you do:

Code:
If (Not IsNumeric(txtqty15.Value)) and len(txtqty15.value)>0 Then

?
 

Watch MrExcel Video

Forum statistics

Threads
1,119,002
Messages
5,575,499
Members
412,670
Latest member
Khin Zaw Htwe
Top