dannyboy1982
Board Regular
- Joined
- Mar 6, 2015
- Messages
- 60
Hi,
I have a simple userform that allows the user to enter a part number, a Vlookup then looks in a table of data and returns a value associated with that part number. What I would like is a message box to appear when an invalid part number is entered saying something like "Invalid part number, please try again". I have managed to get the message box to appear, but it is displayed every time a part number is entered - correct or otherwise. Can a anyone shed a light on what I am doing wrong? Many thanks.
I have a simple userform that allows the user to enter a part number, a Vlookup then looks in a table of data and returns a value associated with that part number. What I would like is a message box to appear when an invalid part number is entered saying something like "Invalid part number, please try again". I have managed to get the message box to appear, but it is displayed every time a part number is entered - correct or otherwise. Can a anyone shed a light on what I am doing wrong? Many thanks.
Code:
Sub Commandbutton2_click()
On Error GoTo out
TextBox2.Value = Application.VLookup(TextBox1.Value, Sheets("Pivot table").Range("A5:G500"), 7, False)
If IsNumeric(Me.TextBox2.Value) Then
Me.TextBox2.Value = Format(TextBox2.Value, "0.00")
End If
out:
MsgBox "Try again - Job not found"
End Sub