Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / June 2006

Tip: Looking for answers? Try searching our database.

count recurring yes/no type data

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Peggy Sue - 08 Jun 2006 16:16 GMT
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
growing over period of months.  Is there a way to do a count or something
that would return the number of months this would be increasing, 0=no
increase, 1=increase?
Jan  Feb  Mar  Apr  May  Jun Jul                 Answer
0     1     1      1      1     0   0                    4
1     0     0      0      1     1   0                    2
Bob Phillips - 08 Jun 2006 17:50 GMT
=SUMPRODUCT(--(A2:F2=1),--(B2:G2=1))+1

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
Peggy Sue - 08 Jun 2006 19:29 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.