PC Review


Reply
Thread Tools Rate Thread

Count consecutive repeats

 
 
EV
Guest
Posts: n/a
 
      15th Mar 2007
I'm looking to count the number of consecutive occurances of a 1
without a zero in a table but only if it is a new run. i.e.

Data Result
0 0
1 1
0 0
1 0
1 0
1 3
0 0


A VBA solution is ok

Evan
Australia

 
Reply With Quote
 
 
 
 
Greg Glynn
Guest
Posts: n/a
 
      15th Mar 2007
Evan: Select the range you're counting before you run the macro.

Sub MyCounter()
OneCounter = 0
For Each c In Selection
If c.Value = 0 Then
c.Offset(0, 1).Value = 0
OneCounter = 0
Else
OneCounter = OneCounter + 1
If c.Offset(1, 0).Value = 0 Then
c.Offset(0, 1) = OneCounter
Else
c.Offset(0, 1) = 0
End If
End If
Next c
End Sub

[Tested OK]

Select the range you're counting before you run the macro.





 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Count repeats RobertM Microsoft Access Queries 1 9th Sep 2009 02:38 AM
How can I count the number of repeats in a list of data? =?Utf-8?B?U291dGhDYXJvbGluYQ==?= Microsoft Excel Misc 7 7th Mar 2006 10:03 PM
Count Intervals of 2 Consecutive Values in same Row and Return Count across Row Sam via OfficeKB.com Microsoft Excel Worksheet Functions 6 29th Nov 2005 03:27 PM
Count repeats =?Utf-8?B?RGFuaWVsIEJvbmFsbGFjaw==?= Microsoft Excel Worksheet Functions 7 10th Dec 2004 05:13 PM
Count new occurances and not repeats morry Microsoft Excel Programming 1 2nd Jul 2004 06:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:12 AM.