Friday, September 3, 2021

VBA IsInArray find in array and return last index

 


Function IsInArray(stringToBeFound As String, arr As Variant) As Long

  Dim i As Long

  ' default return value if value not found in array

  IsInArray = -1


  For i = LBound(arr) To UBound(arr)

    If StrComp(stringToBeFound, arr(i), vbTextCompare) = 0 Then

      IsInArray = i

      Exit For

    End If

  Next i

End Function