Thread: Vlookup Problem
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.misc
aftamath77 aftamath77 is offline
external usenet poster
 
Posts: 30
Default Vlookup Problem

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