Maybe :
Sub DataGenerator()
Dim a(1 To 2993, 1 To 42), i As Long, j As Long
For i = 1 To UBound(a, 1)
For j = 1 To UBound(a, 2)
If Rnd() > 0.5 Then a(i, j) = "X"
Next j
Next i
Application.ScreenUpdating = False
Range("A2").Resize(UBound(a, 1), UBound(a, 2)).Value = a
Application.ScreenUpdating = True
End Sub
Sub GetMaxCount()
Dim a(), b(), i As Long, j1 As Long, j2 As Long, c As Long, cf As Long, t As Long, tf As Long
a = Range("A2").Resize(2993, 42).Value
ReDim b(1 To UBound(a, 1), 1 To 2)
For i = 1 To UBound(a, 1)
cf = 0: tf = 0
For j1 = 1 To UBound(a, 2)
If Not IsEmpty(a(i, j1)) Then
c = j1: t = 0
For j2 = j1 To UBound(a, 2)
If Not IsEmpty(a(i, j2)) Then
t = t + 1
Else
j1 = j2
Exit For
End If
Next j2
If t > tf Then
cf = c: tf = t
End If
End If
Next j1
If tf >= 6 Then
b(i, 1) = cf
b(i, 2) = tf
End If
Next i
Application.ScreenUpdating = False
Range("AR2").Resize(UBound(b, 1), UBound(b, 2)).Value = b
Application.ScreenUpdating = True
End Sub
Bookmarks