VBA alternative to Index Match **Make it better**

Roderick_E

Well-known Member
Joined
Oct 13, 2007
Messages
2,051
So I created a UDF that behaves like MATCH or INDEX MATCH but only on one criteria. I wish I knew enough to redesign it to function on unlimited criteria (within reason obviously). Here it is:

Code:
Function quickcompare(itemtofind As Range, comprange As Range, Optional resultreturn As Range)
'syntax quickcompare(cell,entire match column,optional entire result column)
‘syntax example: =quickcompare(A2,[Book2]Sheet1!$F:$F,[Book2]Sheet1!$G:$G) dragdown
On Error Resume Next
resultcol = ""
resultcol = Replace(Left(resultreturn.Address, InStr(resultreturn.Address, ":") - 1), "$", "")
hitrow = "Not found"
Resume Next
If IsError(Application.Match(itemtofind.Value, Workbooks(comprange.Parent.Parent.Name).Sheets(comprange.Parent.Name).Range(comprange.Address), 0)) = False Then
hitrow = Application.Match(itemtofind.Value, Workbooks(comprange.Parent.Parent.Name).Sheets(comprange.Parent.Name).Range(comprange.Address), 0)
End If
If resultcol = "" Then
quickcompare = hitrow
Else
If hitrow <> "Not Found" Then
quickcompare = Workbooks(comprange.Parent.Parent.Name).Sheets(comprange.Parent.Name).Cells(hitrow, resultcol)
Else
quickcompare = hitrow
End If
End If
End Function
 
Last edited:

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Forum statistics

Threads
1,214,913
Messages
6,122,207
Members
449,074
Latest member
cancansova

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