If you want to optionally allow for case sensitivity, then try the following code:
Code:
Public Function ConsecutiveCount(sStr As String, rng As Range, _
Optional blCaseSensitive As Boolean = False) As Long
Dim rCell As Range
Dim iCtr As Long, jCtr As Long
For Each rCell In rng.Cells
With rCell
If blCaseSensitive Then
If .Value = sStr Then
iCtr = iCtr + 1
jCtr = Application.Max(jCtr, iCtr)
Else
iCtr = 0
End If
Else
If UCase(.Value) = UCase(sStr) Then
iCtr = iCtr + 1
jCtr = Application.Max(jCtr, iCtr)
Else
iCtr = 0
End If
End If
End With
Next rCell
ConsecutiveCount = jCtr
End Function
Bookmarks