Hi
i was attempting to create a new function using VBA. However i am unable to run it successfully. The most probable reason from my end is my inability to pass the cell references correctly.
Here's the long function that i want to transform into a new function.
=IFERROR(VLOOKUP(A1,Sheet2!$A$1:$C$5,HLOOKUP("Price",Sheet2!$A$1:$C$5,2,FALSE),FALSE),"")
This function is actually used to lookup a value corresponding to given parameters
Sample Table:
Model |
Company |
Price |
1 |
2 |
3 |
iPad |
Apple |
1000 |
Galaxy |
Samsung |
2000 |
Lumia |
Nokia |
3000 |
The resultant new function should be something like
=value_find(A1,Sheet2!$A$1:$C$5,"Price")
I have written the VBA code for the same as
Function value_find(Test_Value, ByVal Table_Name As Range, Col_Name)
A = Application.HLookup(Col_Name, Table_Name, 2, False)
B = Application.VLookup(Test_Value, Table_Name, A, False)
value_find = B
End Function
This code doesn't return any compile error. However, when used the only value it returns is "0"
Pls advise on the corrections required.
Thanks so much
Bookmarks