Link to home
Start Free TrialLog in
Avatar of Professor J
Professor J

asked on

help needed with User Define Function Replacing INDEX and MATCH

I was looking to replicate and make it much easier to use the Index and Match function to one UDF


although it works, but  it seems to be very slow comparing to the real index and match. also  i could not figure out how to handle the error becuase if the value is not found, then it gives "VALUE" error.  i was wondering if any of you experts have a better idea to share.

thanks.


Public Function II_WAY_LOOKUP(Lookup_Value As Variant, Reference_Column As Range, Result_Column As Range)
    II_WAY_LOOKUP = WorksheetFunction.Index(Result_Column, WorksheetFunction.Match(Lookup_Value, Reference_Column, 0), 1)
End Function

Open in new window

SOLUTION
Avatar of rspahitz
rspahitz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Professor J
Professor J

ASKER

@rspahitz   thanks. i used your code, and it gave me circular references error. so it did not work like the original code.

@Phillip   thanks.  on error option gives me the "Error" string , however i was wondering if it could return the standard #N/A error, like it normally does in Index and Match. would this be possible?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Change "Error" to CVErr(xlErrNA)
One second difference. :-)
:)

thank you very much all of you.
JimJam, "it gave me circular references error"
It wasn't intended as a completed function (see line 11)...I just didn't want to add more (since I only had a few minutes to write it) if you wanted to avoid going that direction.
Thank you Rspahits