1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| Option Explicit
Public Function FINDMATCH(ByVal sLookupValue As String, _ ByVal rgeLookupArray As Range) As Integer Dim ilow As Integer Dim ihigh As Integer Dim imiddle As Integer
ilow = 0 ihigh = rgeLookupArray.Cells.Count Do While ilow <= ihigh imiddle = (ilow + ihigh) / 2 If VBA.StrComp(sLookupValue, rgeLookupArray.Cells(imiddle, 1).Value, _ VbCompareMethod.vbTextCompare) = 0 Then FINDMATCH = imiddle Exit Function End If If VBA.StrComp(sLookupValue, rgeLookupArray.Cells(imiddle, 1).Value, _ VbCompareMethod.vbTextCompare) = -1 Then ihigh = imiddle - 1 Else ilow = imiddle + 1 End If Loop Call MsgBox("This entry has not been found") FINDMATCH = 0 End Function
|