View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Data validation on form

One way:

Option Explicit
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)

Dim ValueIsOk As Boolean
ValueIsOk = False
If IsNumeric(Me.TextBox1.Value) Then
If Val(Me.TextBox1.Value) 3 _
And Val(Me.TextBox1.Value) < 6 Then
'it's ok
ValueIsOk = True
End If
End If

If ValueIsOk Then
Me.Label1.Caption = ""
Else
Cancel = True 'don't leave the textbox
Me.Label1.Caption = "Please enter a value between 3 and 6"
End If

End Sub



sneagle wrote:

Sorry.

VBA UserForm
Textbox

"Leith Ross" wrote:


Hello sneagle,

When you say Excel Form, do you mean a modified Worksheet for data
entry (tab from cell to cell) or a VBA User Form (looks like a Window)?
What type of control is the user typing the number into - TextBox or
ComboBox?

Thanks,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=482691



--

Dave Peterson