Quite a challenge! I gotta think there's an easier way, but this is what I came up with:
| A | B | C | D | E | F | G | H |
---|
A | B | C | D | Consecutive Sum Max | | | | |
| | | | | | | | |
| | | | | | | | |
| | | | | | | | |
| | | | | | | | |
<tbody>
[TD="align: center"]1[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: center"]2[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"][/TD]
[TD="align: right"]7[/TD]
[TD="align: right"][/TD]
[TD="align: right"]7[/TD]
[TD="align: center"]3[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"][/TD]
[TD="align: right"]0[/TD]
[TD="align: right"][/TD]
[TD="align: right"]0[/TD]
[TD="align: center"]4[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"][/TD]
[TD="align: right"]5[/TD]
[TD="align: right"][/TD]
[TD="align: right"]5[/TD]
[TD="align: center"]5[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]7[/TD]
[TD="align: right"][/TD]
[TD="align: right"]7[/TD]
[TD="align: right"][/TD]
[TD="align: right"]7[/TD]
</tbody>
Sheet8
[TABLE="width: 85%"]
<tbody>[TR]
[TD]
Worksheet Formulas[TABLE="width: 100%"]
<tbody>[TR]
[TH]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
[TR]
[TH]H2[/TH]
[TD="align: left"]=maxconsecutive(
A2:D2)[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="width: 85%"]
<tbody>[TR]
[TD]
Array Formulas[TABLE="width: 100%"]
<tbody>[TR]
[TH]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
[TR]
[TH]F2[/TH]
[TD="align: left"]{=AGGREGATE(
14,6,SUBTOTAL(9,OFFSET(A2,0,SMALL(IF(COLUMN(A2:D2)=COLUMN(A2),0,IF(A2:D2>2,IF(SUBTOTAL(9,OFFSET(A2,0,COLUMN(A2:D2)-COLUMN(A2)-1))<2,COLUMN(A2:D2)-COLUMN(A2)))),COLUMN(A2:D2)-COLUMN(A2)+1),1,IF(COUNTIF(B2:D2,">=2")+1=COLUMNS(A2:D2),COLUMNS(A2:D2),TRANSPOSE(FREQUENCY(IF((A2:D2>=2)+(COLUMN(A2:D2)=COLUMN(A2)),COLUMN(A2:D2)),IF((A2:D2<2)*(COLUMN(A2:D2)<>COLUMN(A2)),COLUMN(A2:D2)))))))-IF((COLUMN(A2:D2)=COLUMN(A2))*(A2:D2<2),A2:D2,0),1)}[/TD]
[/TR]
</tbody>[/TABLE]
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself[/TD]
[/TR]
</tbody>[/TABLE]
The formula in F2 is an array formula, confirm with Control+Shift+Enter. It should be adaptable to wider ranges, just change the ranges in the formula. Be careful though, the range in the COUNTIF starts at the second column.
What is probably a better idea is to use a User-Defined Function (UDF). The formula probably took me a couple hours to derive, the UDF about 3 minutes. To install it, open a copy of your workbook. Press Alt-F11 to open the VBA editor. From the menu, select Insert > Module. On the sheet that opens, paste this code:
Code:
Public Function MaxConsecutive(ByVal target As Range)
Dim c As Range, CurMax As Double
For Each c In target
If c.Value < 2 Then
MaxConsecutive = WorksheetFunction.Max(CurMax, MaxConsecutive)
CurMax = 0
Else
CurMax = CurMax + c.Value
End If
Next c
MaxConsecutive = WorksheetFunction.Max(CurMax, MaxConsecutive)
End Function
Press Alt-Q to close the editor. Now just enter the formula in H2. Much simpler!
Hope this helps.