Thread: Vlookup Problem
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
Mike H Mike H is offline
external usenet poster
 
Posts: 11,501
Default Vlookup Problem

Hi,

Try this. I've left setfocus in but doubt it will work AFAIK it's vey buggy.
so you'll have to re-select manually.

Private Sub TextBox3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim varDN As Variant
If TextBox3.Value < "" Then
varDN = Application.VLookup(TextBox3.Value,
Worksheets("CETables").Range("O:O"), 1, False)
End If
If IsError(varDN) And TextBox3.Value < "" Then
MsgBox "Non-Standard DN Value"
TextBox3.Value = ""
TextBox3.SetFocus
End If
End Sub

Mike
"aftamath77" wrote:

I have a userform with textbox3. The user enters a value into textbox3.
When the user moves to the next userform control, I want VBA to check the
value entered in textbox3 against a table I have on a worksheet (CE Tables).
If the value exists in the table, the focus will move to the next control,
but if the value doesn't exist, I want a msgbox to give a warning, then clear
the value and return to textbox3. Currently, I get a "Type Mismatch" with
MsgBox varDN.Value.

Private Sub TextBox3_Exit(ByVal Cancel As MSForms.ReturnBoolean)

Dim varDN As Variant

varDN = Application.VLookup(TextBox3.Value, Worksheets("CE
Tables").Range("O:O"), 1, False)
MsgBox varDN.Value

If IsError(varDN) = True And TextBox3.Value < "" Then
MsgBox "Non-Standard DN Value"
TextBox3.Value = ""
Textbox3.SetFocus
End If

End Sub