View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Herbert Seidenberg Herbert Seidenberg is offline
external usenet poster
 
Posts: 1,180
Default Finding the longest contiguous 1-d array of 0's

Assume you have a list like this:
XYZ 2 0 4 0 0 6 0 0 0 1
RST 1 0 0 0 0 4 3 0 0 1
MNO 4 7 0 0 0 0 0 4 0 2

Define this 3x11 array as MyArray.
Define another adjacent 3x11 array as MyAccu.
Insert Name Define CSet and RSET respectively
=COLUMN(INDEX($1:$1,,1):INDEX($1:$1,,COLUMNS(MyArr ay)))
=ROW(INDEX($A:$A,1,):INDEX($A:$A,ROWS(MyArray),))
Tools Options Calculations Iterate 11 (your number of columns)
Select MyAccu and enter this array formula:
=IF(INDEX(MyArray,RSet,CSet-1)=0,INDEX(MyAccu,RSet,CSet-1)+1,0)
Adjacent, select a 3x1 column and enter this array formula:
=MAX(INDEX(MyAccu,RSet,))
The result should look like this:
0 0 0 1 0 1 2 0 1 2 3 3
0 0 0 1 2 3 4 0 0 1 2 4
0 0 0 0 1 2 3 4 5 0 1 5
You can hide MyAccu if desired.
The last column will show the maximum number
of adjacent 0's in a row in MyArray
Caveat: The last date is ignored to make things simple.