PDA

View Full Version : Solved: Vlookup Question



bopo
01-10-2009, 08:06 PM
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.

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)

nst1107
01-10-2009, 09:34 PM
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:Worksheets("AddOrder").[A4] = Application.Lookup(StrCustomerName, Worksheets("CustomerDetails").[B1:B100], Worksheets("CustomerDetails").[A1:A100])

bopo
01-11-2009, 07:24 AM
Works perfectly, and yeah I see what you mean, thanks!