Vlookup What if not Found

  • Thread starter Thread starter ssjody
  • Start date Start date
S

ssjody

How do I make this code not error if the value in cboCarPartModel is
not found in my wo worksheet? It works fine if the value is found but
errors if not found. Jody

Private Sub cboCarPartModel_Change()
Dim wo As Range
Set wo = Worksheets("cpModels").Range("cpModelNameAndNumbers")
If Me.cboCarPartModel.Value > "" Then
Label3.Caption = Application.VLookup(cboCarPartModel.Value, wo, 2,
False)
End If
End Sub
 
Hi SS,

One way:

Private Sub cboCarPartModel_Change()
Dim wo As Range
Set wo = Worksheets("cpModels").Range("cpModelNameAndNumbers")
If Me.cboCarPartModel.Value > "" Then
On Error Resume Next
Label3.Caption = _
Application.VLookup(cboCarPartModel.Value, wo, 2, False)
If Err.Number <> 0 Then MsgBox "Not found!"
On Error GoTo 0
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top