VLOOKUP via UDF?

dplum

Board Regular
Joined
Nov 1, 2006
Messages
217
I'm wanting to simplify the creaion of a "lookup" by creating a UDF to do a VLOOKUP.

The only thing the user needs to supply is teh Lookup Value. Everything else is "hard coded".

Also, Range Names are assigned to the Table Array area and also a cell that is located in teh Col_index_num column.

Here's the code, but is doesn't work -- it returns a #VALUE error.

Code:
Function Page_Commission_Rate(Lookup_Value)
    'Worksheet Names are used to assign values to two variables that follow
    vTable_Array_Name = ['] & ThisWorkbook.Name & ['!] & "Table_Array"
    vCol_Index_CellName = ['] & ThisWorkbook.Name & ['!] & "Lookup_Commission"
    vCol_Index_Num = Range(vCol_Index_CellName).Column

    Page_Commission_Rate = WorksheetFunction.VLookup(Lookup_Value, _
                                                vTable_Array_Name, _
                                                vCol_Index_Num, False)
End Function

Help on what's needed to make this work is appreciated.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
If you don't pass all the arguments the function needs, Excel will see no dependency between the contents of the lookup table and the cell your formula is in, and not recalculate when it changes.
 
Upvote 0
Sorry... I'm not understnading what I may need to change.

As far as I know I am pAssing all of the vlookup arguments -- as shown in...

Page_Commission_Rate = WorksheetFunction.VLookup(Lookup_Value, _
vTable_Array_Name, _
vCol_Index_Num, False)
 
Upvote 0
All the function receives as an argument is the lookup value -- not the table, not the column index.
 
Upvote 0
But the Table and Column Index are specified as variables within the UDF. And the VALUE error is given from the initial insert of the UDF, not just on a recalc.
 
Upvote 0
None of that gives Excel a whit of a hint that the function is dependent on the values in the table or the column index.
 
Upvote 0

Forum statistics

Threads
1,214,813
Messages
6,121,706
Members
449,049
Latest member
THMarana

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