Average number of consecutive 0s

sarwar8

New Member
Joined
Nov 26, 2016
Messages
4
I have cells in the C column. Many of the cells have values, while others have interspersed "0"s. I want to know the average number of consecutive zeros. For example: 1,0,0,0,0,5,0,0,6 should give me an average of 3.


I am also interested in finding the average number of consecutive 0s, only if there are 3 or more 0s in a row. With the above example, the two 0s in a row wouldn't count, and the average would be 4.

Thank you!
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
1. Control+shift+enter, not just enter:

=AVERAGE(IF(FREQUENCY(IF(ISNUMBER(A2:A10),IF(A2:A10=0,ROW(A2:A10))),IF(1-(A2:A10=0),ROW(A2:A10))),FREQUENCY(IF(ISNUMBER(A2:A10),IF(A2:A10=0,ROW(A2:A10))),IF(1-(A2:A10=0),ROW(A2:A10)))))

2. Control+shift+enter, not just enter:

=AVERAGE(IF(FREQUENCY(IF(ISNUMBER(A2:A10),IF(A2:A10=0,ROW(A2:A10))),IF(1-(A2:A10=0),ROW(A2:A10)))>=3,FREQUENCY(IF(ISNUMBER(A2:A10),IF(A2:A10=0,ROW(A2:A10))),IF(1-(A2:A10=0),ROW(A2:A10)))))
 
Upvote 0
Here's a VBA option:

Code:
Private Sub CommandButton1_Click()
Dim r, check, i, count As Integer
Dim zeros() As Integer


r = Worksheets(1).Range("C:C").End(xlDown).Row
For check = 1 To r
    If Cells(check, 3).Value = 0 Then
        ReDim Preserve zeros(i)
        count = count + 1
        zeros(i) = count
    ElseIf count > 0 Then
        i = i + 1
        count = 0
    End If
Next check


Range("D1").Value = Application.WorksheetFunction.Average(zeros)
End Sub

Regards,

CJ
 
Upvote 0

Forum statistics

Threads
1,215,239
Messages
6,123,818
Members
449,127
Latest member
Cyko

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