View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bernie Deitrick Bernie Deitrick is offline
external usenet poster
 
Posts: 5,441
Default VB's equivalent to VLOOKUP?

Dan,

Put your lookup table is in a range, then simply use

Application.Worksheetfunction.Vlookup(....)

The big difference is that instead of using the function as you do in the
worksheet:

=VLOOKUP(D1, A1:B3, 2, False)

You would use:

Y = value from the Listbox
X = Application.Worksheetfunction.Vlookup(Y, Range("A1:B3"), 2, False)

HTH,
Bernie
MS Excel MVP

"Dan" wrote in message
...
Is there a VB Equivalent to Excel's Vlookup Formula.

Lets say that I have three names in a list box.

1. Dan
2. Jim
3. Doug

The Variable I want to pass on is a value associated with
one of the 3 items.

Name (From Listbox), Salary

Dan, 50000
Jim, 60000
Ted, 70000

Lets say my variable is X.

How would I get X to be the set equal to the salary when
one of the names is selected.

I know I could create another varaiable called Y and set
that equal to the lstbox.value and then use an if then
statement. But with a lot of names that could become very
labor intensive to create. Any ideas.

Thanks

Dan