Macro Code for replacing Index/Match based on input for "lookup value" and "lookup array"

IosifFlorin

New Member
Joined
Jul 1, 2015
Messages
18
Hi,

i am trying to build a macro code for a function that will replace the index/match function (trying to make it simpler.

What i build:

Function FLook(myRange, LookupValue)


test = Application.WorksheetFunction.Index(myRange, Application.WorksheetFunction.Match(LookupValue, ProdCodBandings, 0))


End Function

and how i want to apply it in excel is something like this (having this in a table so referencing @ a cell in the table that will vary depending on the the difference value). Price1SA is a range predefined.

=FLook(Price1SA,[@[Product Code]])


Any idea what to adjust in order to work? Maybe some variables to define?


Thank you!
Iosif
 
Heres a function that ive just written which works a bit like index match. You use it like this for example:

=leftlookup(H1,D2:D3,A2:A3)

Where H1 contains the value to find in D2:D3 and A2:A3 is the return range.

Code:
Function leftlookup(lookup_value As String, lookup_range As Range, result_range As Range)

With lookup_range
    Set x = .Find(lookup_value, LookIn:=xlValues, LookAt:=xlWhole)
    If Not x Is Nothing Then
        myval = WorksheetFunction.Match(lookup_value, lookup_range)
        leftlookup = WorksheetFunction.Index(result_range, myval)
        Else
        leftlookup = CVErr(xlErrNA)
    End If
End With

End Function
 
Upvote 0

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