Same digit in a row

hemsleysut

Board Regular
Joined
Jul 29, 2002
Messages
124
I have 0s and 1s randomly placed to fill a grid of 20cols. by 120rows. Is there a VBA procedure that will return the total number of rows where a 1 appears 5 times consecutively. Any help is greatly appreciated.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

jindon

MrExcel MVP
Joined
Aug 21, 2004
Messages
16,995
Hi
Code:
Sub test()
Dim i As Long, ii As Long, n As Long
For i = 1 To 116
     For ii = 1 To 20
          If WorksheetFunction.CountIf(Cells(i,ii).Resize(5),1)=5 Then n = n + 1
     Next
Next
MsgBox n
End Sub
 
Upvote 0

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,892
Hi hemsleysut

3 questions:

- if there is more than 1 sequence of 5 1s in a row does it still count just as 1?

- In case the answer was no, what about sequences that overlap? If A1:F1=1 do we have 2 sequences (A1:E1,B1:F1)?

- Why vba?

Kind regards
PGC
 
Upvote 0

Forum statistics

Threads
1,191,120
Messages
5,984,762
Members
439,909
Latest member
daigoku

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top