+ Reply to Thread
Results 1 to 3 of 3

Vlookup What if not Found

  1. #1
    ssjody
    Guest

    Vlookup What if not Found

    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


  2. #2
    Norman Jones
    Guest

    Re: Vlookup What if not Found

    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


    ---
    Regards,
    Norman



    "ssjody" <jbprather@fuse.net> wrote in message
    news:1135428230.686025.279090@g49g2000cwa.googlegroups.com...
    > 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
    >




  3. #3
    ssjody
    Guest

    Re: Vlookup What if not Found

    Thanks Norman! Works Great!


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1