' Max length of chain in series after ResetVal with skipping of empty values
' Cell formula: =MaxLengh(A2:A100,"dual")
' VBA call : MsgBox MaxLengh(Range("A2:A100"),"dual")
Function MaxLengh(Series, ResetVal) As Long
Dim arr, old, v$, x, y&
arr = Series
For Each x In arr
v = Trim(x)
If Len(v) > 0 Then
If StrComp(v, ResetVal, vbTextCompare) = 0 Then
y = 0
MaxLengh = 0
old = Empty
ElseIf StrComp(v, old, vbTextCompare) = 0 Then
y = y + 1
If y > MaxLengh Then MaxLengh = y
If StrComp(v, ResetVal, vbTextCompare) = 0 Then y = 0: MaxLengh = 0
Else
y = 1
old = v
End If
End If
Next
End Function