Just a couple of tweaks:
Function RVLOOKUP(target, criteriaCellRange, colIndex)
Dim found As Boolean
Dim resultCell As Range
For Each cell In criteriaCellRange
matchPosition = InStr(cell, target)
If matchPosition > 0 Then
found = True
Set resultCell = cell
Exit For
End If
Next cell
If found Then
' Here resultCell seems to be just a String not an actual cell object
RVLOOKUP = resultCell.Offset(0, colIndex)
Else
RVLOOKUP = "#NoMatch"
End If
End Function
I reverse the InStr()
arguments and made resultCell
a Range
Without recourse to O365
, and given your wish to avoid formulas which require CTRL+SHIFT+ENTER
, this will necessitate a rather lengthy construction, for example:
=IF(COUNTIFS(A2:A13,F1,B2:B13,">="&F2),INDEX(C2:C13,MATCH(AGGREGATE(15,6,B2:B13/((A2:A13=F1)*(B2:B13>=F2)),1),INDEX(B2:B13/((A2:A13=F1)*(B2:B13>=F2)),),0)),"No Result")
Although less intelligible, the following is a more concise and less resource-intensive alternative:
=IF(COUNTIFS(A2:A13,F1,B2:B13,">="&F2),LOOKUP(1,0/FREQUENCY(0,(0.5+(B2:B13-F2))*8^8^(A2:A13<>F1)),C2:C13),"No Result")
Although note that, unlike the first, this second solution may fail if the entries in F2
and B2:B13
are not all integers.
The initial COUNTIFS
clause is used to first determine whether there are in fact any rows which meet your criteria.
Best Answer
book ends the values with spaces, and lookup is probably not the best tool for this: