
Signature
HTH
Bob Phillips
(replace somewhere in email address with gmail if mailing direct)
> I am not sure if this is possible..... I am working in a large spreadsheet
> containing inventory counts. I want to be able to display if an item is
[quoted text clipped - 4 lines]
> 0 1 1 1 1 0 0 4
> 1 0 0 0 1 1 0 2
Thanks for your reply. This won't show me the the number of consecutive
months for each row that have a value of 1 will it? I am looking to count
the highest number of recurring "1"s. Maybe Excel can't do this......
Another Example
Part# jan feb mar apr may jun Answer:
65145 0 0 0 1 1 1 3
64135 1 1 1 1 0 1 4
68112 1 0 1 1 1 0 3
> =SUMPRODUCT(--(A2:F2=1),--(B2:G2=1))+1
>
[quoted text clipped - 7 lines]
> > 0 1 1 1 1 0 0 4
> > 1 0 0 0 1 1 0 2
Bob Phillips - 09 Jun 2006 10:04 GMT
It gets exactly those answer in my tests. Needs to be adjusted to the
ranges, =SUMPRODUCT(--(B2:F2=1),--(C2:G2=1))+1, but other than that ...

Signature
HTH
Bob Phillips
(replace somewhere in email address with gmail if mailing direct)
> Thanks for your reply. This won't show me the the number of consecutive
> months for each row that have a value of 1 will it? I am looking to count
[quoted text clipped - 18 lines]
> > > 0 1 1 1 1 0 0 4
> > > 1 0 0 0 1 1 0 2
Peggy Sue - 09 Jun 2006 13:45 GMT
You are right - I must have entered it wrong the first time - thank you!
> It gets exactly those answer in my tests. Needs to be adjusted to the
> ranges, =SUMPRODUCT(--(B2:F2=1),--(C2:G2=1))+1, but other than that ...
[quoted text clipped - 27 lines]
> > > > 0 1 1 1 1 0 0 4
> > > > 1 0 0 0 1 1 0 2
kounoike - 09 Jun 2006 12:03 GMT
This way is to make UDF something like
Function counttest(rng As Range) As Long
Application.Volatile
Dim st0 As Boolean, st1 As Boolean
Dim s As Long, state As Long, j As Long
Dim rec() As Long
ReDim rec(rng.Count)
st0 = False
st1 = False
For Each rng In rng
If rng.Value = 1 Then
st1 = True
Else
st1 = False
End If
If st0 And st1 Then
state = 1
ElseIf st0 And (Not st1) Then
state = 2
ElseIf (Not st0) And st1 Then
state = 3
End If
Select Case state
Case 1
s = s + 1
Case 2
rec(j) = s
j = j + 1
s = 0
st0 = st1
Case 3
s = s + 1
st0 = st1
Case Else
End Select
Next
counttest = Application.Max(rec)
End Function
and apply this function in your worksheet.
assumeing your data are populated in "b2:g2" and answer in "i2", then
put the formula in "i2"
=countertest(B2:G2)
will return 3.
if you need a answer in "i3", drag and copy above formula to "i3".
keizi
> Thanks for your reply. This won't show me the the number of consecutive
> months for each row that have a value of 1 will it? I am looking to count
[quoted text clipped - 18 lines]
> > > 0 1 1 1 1 0 0 4
> > > 1 0 0 0 1 1 0 2