Another VLookup question.

L

Legacy 98055

Guest
Hi all.
I am using the VLookup function in VBA and can not get it to work. Please help...

Ex.

<pre>


| A | B |
|______________|_________________|
1 | 1300 | How |
|______________|_________________|
2 | 1518 | Are |
|______________|_________________|
3 | 1614 | You |
|______________|_________________|
4 | 2001 | Doing |
|______________|_________________|
5 | 2124 | Today |
|______________|_________________|


</pre>

The range A1:B5 is named:
E_List

How do I incorporate this named range into
my VLookup function?

Here is my current code. I keep getting an error.

<pre>


CurrentDept = "1518"

Set E_AddressRange = ActiveWorkbook.Names("E_List")

E_Address = Application.WorksheetFunction.VLookup(Val(CurrentDept), E_AddressRange, 2)


</pre>


E_Address should return "Are"

Another question:
Can I also get this function to return the row number?
In this example RowNum would equal 2.

Thanks,
Tom
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
The following UDF (User Defined Function) works. I used named ranges Code and E_List.

Use Function as =LookupA(CODE, E_List)

Function LookupA(CODE, E_List)
If CODE <> "" Then
With Application.WorksheetFunction
LookupA = .VLookup(CODE, E_List, 2, False)
End With
Else
LookupA = ""
End If
End Function
 
Upvote 0
Thanks Dave,
Works perfectly...
I was about to give up on this one and just code the formula to a worksheet and use it from there...
Thanks Again!
Tom
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,256
Members
448,557
Latest member
richa mishra

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top