Count consecutive occurrences of only 1

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,422
Office Version
  1. 2010
Happy New Year to everyone

Hello,

I am looking VBA solution, which count the constant occurrences of 1 only

Data got in cells C6:P22,

Results shown in R6 AF22

Sample Data


Book1
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAH
1
2
3
4
5P1P2P3P4P5P6P7P8P9P10P11P12P13P14P1P2P3P4P5P6P7P8P9P10P11P12P13P14P15
6o1ooo1111o11oo142
7oo1o1oooo1ooo11111
8oo1o1oo11oooo11121
9oo11ooo1o1oooo211
101oo1o1111o111o1143
111ooo1o11oo11111124
12oo1ooooo1111oo14
13o11o1o11111o112152
141ooooo1o1o11111114
15ooooo111o1o11o312
16111o1111oo1o113412
17oo1oooo1o111oo113
18oo1o1oo11o11o111221
19oooooo1o1111oo14
201o11o1111oooo11241
21ooooooooooooo11
22111111o111111167
23
Sheet1



Thank you all
Excel 2000
Regards,
Moti
 
Hello, again whether it is solved. Please I want results in single column could be changed as shown below


Book1
ABCDEFGHIJKLMNOPQRS
1
2
3
4
5P1P2P3P4P5P6P7P8P9P10P11P12P13P14Results
6o1ooo1111o11oo1 | 4 | 2
7oo1o1oooo1ooo11 | 1 | 1 | 1
8oo1o1oo11oooo11 | 1 | 2 | 1
9oo11ooo1o1oooo2 | 1 | 1
101oo1o1111o111o1 | 1 | 4 | 3
111ooo1o11oo11111 | 1 | 2 | 4
12oo1ooooo1111oo1 | 4
13o11o1o11111o112 | 1 | 5 | 2
141ooooo1o1o11111 | 1 | 1 | 4
15ooooo111o1o11o3 | 1 | 2
16111o1111oo1o113 | 4 | 1 | 2
17oo1oooo1o111oo1 | 1 | 3
18oo1o1oo11o11o11 | 1 | 2 | 2 | 1
19oooooo1o1111oo1 | 4
201o11o1111oooo11 | 2 | 4 | 1
21ooooooooooooo11
22111111o11111116 | 7
23
24
Sheet2


Thank you

Regards,
Moti
 
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Here is a modified code for you to try:
Code:
Sub Test1()
    Dim tmparr, i As Long, j As Long
    For i = [COLOR=#ff0000]6[/COLOR] To [COLOR=#ff0000]22[/COLOR]
        tmparr = Split(WorksheetFunction.Trim(Replace(Join(WorksheetFunction.Index( _
            Range("C" & i & ":P" & i).Value, 1, 0), ""), "o", " ")), " ")
        For j = 0 To UBound(tmparr)
            tmparr(j) = Len(tmparr(j))
        Next j
        Cells(i, "R") = Join(tmparr, " | ")
    Next i
    Range("R[COLOR=#ff0000]6[/COLOR]:R[COLOR=#ff0000]22[/COLOR]").NumberFormat = "@"
End Sub
 
Upvote 0
Here is a modified code for you to try:
Code:
Sub Test1()
    Dim tmparr, i As Long, j As Long
    For i = [COLOR=#ff0000]6[/COLOR] To [COLOR=#ff0000]22[/COLOR]
        tmparr = Split(WorksheetFunction.Trim(Replace(Join(WorksheetFunction.Index( _
            Range("C" & i & ":P" & i).Value, 1, 0), ""), "o", " ")), " ")
        For j = 0 To UBound(tmparr)
            tmparr(j) = Len(tmparr(j))
        Next j
        Cells(i, "R") = Join(tmparr, " | ")
    Next i
    Range("R[COLOR=#ff0000]6[/COLOR]:R[COLOR=#ff0000]22[/COLOR]").NumberFormat = "@"
End Sub
Tetra201, very much appreciated! Code is working as treat

Thank you so much for your kind help and modifying it.

Regards,
Moti

 
Upvote 0

Forum statistics

Threads
1,223,705
Messages
6,173,994
Members
452,542
Latest member
Bricklin

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