+ Reply to Thread
Results 1 to 4 of 4

Len(VLookup()) Error

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Len(VLookup()) Error

    I know there are instances where the Vlookup() will not find a value. When it does not I want it to pop up secondary list. The problem is the Vlookup() errors out when it can't find a value.

        Dim iopcert As Variant, hospital As Variant, miss_hosp As String, inp_form As Worksheet
        Dim ocd1 As Worksheet, hosp_form As NoOpcert, lngindex As Long
        
        iopcert = Application.InputBox(prompt:="Enter the hospitals opcert #" & i, Title:="OPCERT" & i, Left:=300, Top:=250, Type:=1)
        Set ocd1 = ActiveWorkbook.Sheets("OPCERT")
        
        If Len(Application.WorksheetFunction.VLookup(iopcert, ocd1.Range("A1:C187"), 2, False)) = 0 Then
            Set hosp_form = NoOpcert
            With hosp_form
                .Show
                miss_hosp = .hosp_list.Value
            End With
            Unload hosp_form
            Set hosp_form = Nothing
            If lngindex = -1 Then
                MsgBox "Nothing was selected!"
            Else
            End If
        Else
            hospital = Application.WorksheetFunction.VLookup(opcert, ocd1.Range("A1:C187"), 2, False)
        End If
    Any idea how to get around this?

  2. #2
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: Len(VLookup()) Error

        If IsError(Application.WorksheetFunction.VLookup(iopcert, ocd1.Range("A1:C187"), 2, False)) = True Then
    didn't work either. I still get a run-time error: 1004 Unable to get the Vlookup() property of the worksheet function class.

  3. #3
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: Len(VLookup()) Error

    If IsError(Application.WorksheetFunction.VLookup(iopcert, ocd1.Range("A1:C187"), 2, False)) = 2042 Then
    Since it's an N/A error the above code should work, but alas it fails...

  4. #4
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Cool Re: Len(VLookup()) Error

    On Error GoTo Secondary_List:
        hospital = Application.WorksheetFunction.VLookup(iopcert, ocd1.Range("A1:C187"), 2, False)
        
    Secondary_List:
            Set hosp_form = NoOpcert
            With hosp_form
                .Show
                miss_hosp = .hosp_list.Value
            End With
            Unload hosp_form
            Set hosp_form = Nothing
            If lngindex = -1 Then
                MsgBox "Nothing was selected!"
            Else
            End If
    On error goto worked....

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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