Consulting

Results 1 to 3 of 3

Thread: Solved: Vlookup Question

  1. #1

    Solved: Vlookup Question

    Hi

    Well I'm a little intoxicated, however I wrote a simple Vlookup function, basically I want it to lookup a string (a users name in a worksheet, column B) and return the users ID (which is located in column A) into my current worksheet, however I just can't seem to grasp how to return the customers ID back into the AddOrder(A4) cell, help much appreciated.

    [vba]Dim StrCustomerName As String

    StrCustomerName = Application.InputBox("Please enter the customer's name:", "Customer Name")


    Worksheets("AddOrder").Range("A4").Value = Application.VLookup(StrCustomerName, Worksheets("CustomerDetails").Range("A1:B100"), 1, False)[/vba]

  2. #2
    VBAX Tutor nst1107's Avatar
    Joined
    Nov 2008
    Location
    Monticello
    Posts
    245
    Location
    VLookup looks in the first column of the array you specify, so here it is looking in column A for the customer name, where the ID's are. So, it's probably returning #N/A every time. Try this instead:[VBA]Worksheets("AddOrder").[A4] = Application.Lookup(StrCustomerName, Worksheets("CustomerDetails").[B1:B100], Worksheets("CustomerDetails").[A1:A100])
    [/VBA]

  3. #3
    Works perfectly, and yeah I see what you mean, thanks!

Posting Permissions

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