Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Count consecutive cells then start over

832 views
Skip to first unread message

John67

unread,
Jan 16, 2008, 11:08:03 AM1/16/08
to
Hello, I would like to know how to create a simple function which will count
the cells that show up with the number 1 seven consecutive times and then
start over.

For instance, let's say the range is B3:B100, and the number 1 will
occasionally show up 3x's or 5x's and then occasionally 7x's with blank cells
and between each of the sets. I need it to display somewhere at the top of
the spreadsheet when the number 1 has shown up seven consecutive times. Most
importantly, I need it to start the count over again once it runs across a
blank cell.

Any help would greatly be appreciated!

~John~

Don Guillett

unread,
Jan 16, 2008, 11:34:06 AM1/16/08
to
Sub sevenones()
mc = "b"
c = 0
For i = 3 To Cells(Rows.Count, mc).End(xlUp).Row
If Cells(i + 1, mc) = 1 And Cells(i, mc) = 1 Then
c = c + 1
Else
c = 0
End If
'MsgBox c
If c = 7 Then
cells(1,mc)= Cells(i, mc).Address
Exit For
End If
Next i
End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software
dguil...@austin.rr.com
"John67" <Joh...@discussions.microsoft.com> wrote in message
news:BEFAE0D2-E8DD-4AC7...@microsoft.com...

Herbert Seidenberg

unread,
Jan 16, 2008, 1:54:20 PM1/16/08
to
Or without VBA
and without counting 8x's 9x's ...
http://www.freefilehosting.net/download/3aee3

Don Guillett

unread,
Jan 16, 2008, 3:28:56 PM1/16/08
to
If a function is desired, use this formula in any cell desired to locate the
7th consecutive.
=so("e")

Put the below function into a REGULAR vba module
Function so(mc)
c = 0
For i = 2 To Cells(Rows.Count, mc).End(xlUp).Row


If Cells(i + 1, mc) = 1 And Cells(i, mc) = 1 Then
c = c + 1
Else
c = 0
End If
'MsgBox c
If c = 7 Then

so = Cells(i, mc).Address
'Cells(1, mc) = Cells(i, mc).Address


Exit For
End If
Next i

End Function


--
Don Guillett
Microsoft MVP Excel
SalesAid Software
dguil...@austin.rr.com

"Herbert Seidenberg" <herbds...@yahoo.com> wrote in message
news:58fc3d79-8618-4a71...@e25g2000prg.googlegroups.com...

John67

unread,
Jan 16, 2008, 4:03:00 PM1/16/08
to
Thanks Don, but unfortunately it didn't do anything. I do appreciate the
help all the same.

T. Valko

unread,
Jan 16, 2008, 4:16:01 PM1/16/08
to
Try this array formula** :

=SUM(--(FREQUENCY(IF(List1=1,ROW(List1)),IF(List1<>1,ROW(List1)))=Target))

** array formulas need to be entered using the key combination of
CTRL,SHIFT,ENTER (not just ENTER)

--
Biff
Microsoft Excel MVP


"Herbert Seidenberg" <herbds...@yahoo.com> wrote in message
news:58fc3d79-8618-4a71...@e25g2000prg.googlegroups.com...

Don Guillett

unread,
Jan 16, 2008, 4:55:58 PM1/16/08
to
It WAS tested.

I didn't but you may need this as the first line in the function.
Application.Volatile

Did you place in a regular module?
Did you change "e" to your column that has the string of 1's?
Is calculation set to automatic? Touch f9 key to calculate

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
dguil...@austin.rr.com

"John67" <Joh...@discussions.microsoft.com> wrote in message

news:69586A7B-DE42-4934...@microsoft.com...

Don Guillett

unread,
Jan 16, 2008, 5:00:06 PM1/16/08
to
Also, try this modification.

Function so(mc)
Application.Volatile
c = 1


For i = 2 To Cells(Rows.Count, mc).End(xlUp).Row
If Cells(i + 1, mc) = 1 And Cells(i, mc) = 1 Then
c = c + 1
Else

c = 1


End If
'MsgBox c
If c = 7 Then

so = Cells(i + 1, mc).Address


'Cells(1, mc) = Cells(i, mc).Address
Exit For
End If
Next i
End Function

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
dguil...@austin.rr.com

"John67" <Joh...@discussions.microsoft.com> wrote in message
news:69586A7B-DE42-4934...@microsoft.com...

Herbert Seidenberg

unread,
Jan 16, 2008, 5:37:52 PM1/16/08
to
I withdraw my previous post.
Biff's approach is the way to go.

ghost...@gmail.com

unread,
Aug 30, 2013, 3:03:20 AM8/30/13
to
flipping subjects a bit I am looking to count the number of "y" in a row but then start over at a blank cell. can the formula skip every other cell? any formulas available?
i.e.
Attendance
E2="Aug 21" G2="Aug 28" I2="Sept 4"
E5="Class" F5="homework" G5="Class" H5="homework" I5="Class" J5="homework"
C6="John" E6="y" E5="y" G6="y" H5="" I6="" J6=""

the first formula should show that John has been to class 2xs in a row
the second formula should show homework turned 1 out of 3 times.

Is this possible? thanks again for any attempt.
Daniel
0 new messages