
Option Explicit
Function count_sequences_of_negatives(r As Range) As Long
Dim cell As Range, val_cell As Integer, tot As Long, maximum As Long
For Each cell In r.Resize(r.Rows.Count - 1)
val_cell = Val(cell)
If val_cell < 0 Then
tot = tot + 1
If tot > maximum Then maximum = tot
Else
tot = 0
End If
Next
count_sequences_of_negatives = maximum
End Function |
Option Explicit
Function count_negative_sequences(r As Range) As Long
Dim regexp As Object, s As String, matches As Object, match As Object
Dim cnt As Integer, cnt_max As Integer
Set regexp = CreateObject("VBScript.Regexp")
With regexp
.Global = True
.MultiLine = True
.IgnoreCase = False
.Pattern = "(-d *)*"
End With
s = Join(Application.Transpose(r))
If regexp.Test(s) Then
Set matches = regexp.Execute(s)
For Each match In matches
If match <> "" Then
cnt = Len(match & " ") 3
If cnt > cnt_max Then cnt_max = cnt
End If
Next
End If
count_negative_sequences = cnt_max
End Function |
tot = tot + 1
If tot > maximum Then maximum = tot
