Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 39
Default Finding the longest contiguous 1-d array of 0's

Hi All,

Ok, I can't think of any remotely-easy way to do this. My data exists as
such: accounts listed in the rows, dates (by month) listed in the columns;
in the fields corresponding to each account/dates is the quantity of items
the account purchased in that month.

Is it formulaically possible (barring VBA) to have Excel calculate the
longest contiguous string of zero-value cells for each row? (What I'm
trying to discern is a historical gap-analysis for the longest no-purchase
period of a given row/account.) Any thoughts or suggestions are greatly
appreciated, as always.

Thanks,

Jamie W.
  #2   Report Post  
Posted to microsoft.public.excel.misc
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.
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,124
Default Finding the longest contiguous 1-d array of 0's

Try this where text in col a and numbers in col 2-11
Sub findlongestzeros()
For i = 1 To Cells(Rows.Count, "a").End(xlUp).Row
mc = 0
For j = 2 To 11
If Cells(i, j) = 0 And Cells(i, j + 1) = 0 Then mc = mc + 1
Next j
'MsgBox mc
If mc mss Then
mss = mc
mr = i
End If
Next i
MsgBox "Max is Row " & mr
'MsgBox mss
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"MJW" wrote in message
...
Hi All,

Ok, I can't think of any remotely-easy way to do this. My data exists as
such: accounts listed in the rows, dates (by month) listed in the
columns;
in the fields corresponding to each account/dates is the quantity of items
the account purchased in that month.

Is it formulaically possible (barring VBA) to have Excel calculate the
longest contiguous string of zero-value cells for each row? (What I'm
trying to discern is a historical gap-analysis for the longest no-purchase
period of a given row/account.) Any thoughts or suggestions are greatly
appreciated, as always.

Thanks,

Jamie W.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
summing non-contiguous array cells WRC Excel Worksheet Functions 10 November 5th 07 10:26 PM
Multiplying Contiguous Values in an Array [email protected] Excel Worksheet Functions 1 May 26th 07 06:46 AM
Finding non contiguous positive values Nick Krill Excel Worksheet Functions 1 March 29th 07 02:09 AM
Finding last column in non-contiguous range Bob Excel Worksheet Functions 6 February 5th 07 08:58 PM
Weighted avg of numbers not in contiguous row-ie array w lookup? Diane Excel Worksheet Functions 2 November 9th 05 02:12 AM


All times are GMT +1. The time now is 04:24 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"