Hello,

I am writing a binary search function. At the end I check to see if the next element matches the "search for" value. When searching for an element larger than any in the list, my marker lands on the last list element and I get a "subscript out of range" error when trying to check the non-existent next element. To me, if there is no next element then obviously it can't be equal to the value, so the if condition should fail and it should move on to the next line of code. Unfortunately, even when I put "On error resume next" it still gives me the error. How can I ignore the error and move on as if it was false?

My code segment (inArr is the list to be searched, Match is the marker, val is the "search for value, gap/run are options):
On Error Resume Next
            If run = gap And inArr(Match, col) <> val Then Match = U + run
            Exit Function
This gives me an error if Match>UBound(inArr,1) despite the On Error Resume Next.