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

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
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
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,214,979
Messages
6,122,561
Members
449,089
Latest member
Motoracer88

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
Back
Top