Since error 1004 is not trappable (or not in the list of trappable errors), How do I check to see if val is in the named range price?
This is the line I am having problems with.
If WorksheetFunction.IsError(WorksheetFunction.VLookup(val, Range("price"), 2, False)) = True Then
Private Sub Itemnum_AfterUpdate()
On Error Resume Next
Dim val As String
With userforms1
val = Itemnum.Value
'check to see if val is in range price
'if not reset
If WorksheetFunction.IsError(WorksheetFunction.VLookup(val, Range("price"), 2, False)) = True Then
Itemnum.Value = ""
MsgBox ("You have entered an invalid Item Number, Please try again.")
Itemnum.SetFocus
Exit Sub
Else
'populate descrption
desc.Value = WorksheetFunction.VLookup(val, Range("price"), 2, False)
End If
' get priceing
If tog.Value = "True" Then
price.Value = Format(WorksheetFunction.VLookup(val, Range("price"), 6, False), dformat)
Else
price.Value = Format(WorksheetFunction.VLookup(val, Range("price"), 5, False), dformat)
End If
End With
End Sub
Bookmarks