Function MaxContigus(ByVal R, ByVal V, ByVal K) As Double
Dim T(), L As Long, Score As Long, TMax(1 To 3) As Long
If TypeOf R Is Range Then T = R.Value Else T = R
If TypeOf V Is Range Then V = V.Value
If TypeOf K Is Range Then K = K.Value
L = 1
Do:
Do While T(L, 1) <> V
L = L + 1: If L > UBound(T, 1) Then Exit Function
Loop
Score = 0
Do: Score = Score + 1
L = L + 1: If L > UBound(T, 1) Then Exit Do
Loop Until T(L, 1) <> V
Select Case TMax(1)
Case Is < Score: TMax(1) = Score: TMax(2) = 1: TMax(3) = L - 1
Case Is = Score: TMax(2) = TMax(2) + 1
End Select
MaxContigus = TMax(K)
Loop Until L > UBound(T, 1)
End Function