Consulting

Results 1 to 4 of 4

Thread: Solved: VLookup Code Error in form - Runtime Error 1004

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Contributor
    Joined
    Jul 2009
    Posts
    157
    Location

    Solved: VLookup Code Error in form - Runtime Error 1004

    I am trying to create a simple spreadsheet (see attached) with a form that the user would enter the Contributor Number and a Vlookup is performed on a range and when exiting the field would return the Contributor Name and Contributor Address into fields on the form. The code sets the range that is used in the Vlookup. When running this, I get an error: Runtime Error 1004: Unable to get the Vlookup property of the Worksheet Function class.

    I have looked all over the web but cannot find a solution that works in this situation, so I am not sure where to go from here.

    The code I am using is:

    [VBA]
    Private Sub ContributorNumber_Exit(ByVal Cancel As MSForms.ReturnBoolean)

    Dim myrange
    Set myrange = Worksheets("Contributors").Range("A1:B143")

    ContributorName.Value = WorksheetFunction.VLookup(ContributorNumber.Value, myrange, 2, False)
    If Err <> 0 Then
    ContributorName.Value = "N/A"
    End If

    ContributorAddress.Value = WorksheetFunction.VLookup(ContributorNumber.Value, myrange, 3, False)

    If Err <> 0 Then
    ContributorAddress.Value = "N/A"
    End If

    End Sub

    [/VBA]

    Does anyone have an idea why this code is not working ?

    When I tried to debug the code, when I hovered over ContributorNumber.Value, it showed the proper value entered into the form and I used values for ContributorNumber that I knew were present in the range I set-up.

    Any advice would be greatly appreciated ! I think it is probably something small I am overlooking but cannot find it.

    thanks !
    Attached Files Attached Files

Posting Permissions

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