Codice:
Function Stefansen(ByVal sCol As String, ByVal iInizio As Integer, ByVal iFine As Integer, _
ByVal sTesto As String) As Integer
' Cerca nella colonna sCol il massimo di ripetizioni
Dim iRow As Integer, iMax As Integer, iConteggio As Integer
Dim bCheck As Boolean
Dim sCella As String
iRow = iInizio
Do
sCella = Trim(Range(sCol & Trim(iRow)))
If sCella = "" Then
Exit Do
End If
If sCella = sTesto Then
If bCheck = False Then
bCheck = True
iMax = 1
Else
iMax = iMax + 1
End If
Else
If bCheck = True Then
bCheck = False
If iMax > iConteggio Then
iConteggio = iMax
End If
End If
End If
iRow = iRow + 1
If iRow > iFine Then
Exit Do
End If
Loop
Stefansen = iConteggio
End Function