Vba Count range of zeros in a bigger range

lisanne_123

New Member
Joined
May 31, 2018
Messages
6
Hey,

I need te count the amount of ranges with zeros in a bigger range.

Now I have:
Dim nrGaps as Integer
nrGaps = Application.WorksheetFunction.CountIf(Range("E2:AT820"), "0")
Blad4.Cells(2, 1) = nrGaps

But this count the number of zero. Can somebody help?
 
Hey,

I need te count the amount of ranges with zeros in a bigger range.

Now I have:
Dim nrGaps as Integer
nrGaps = Application.WorksheetFunction.CountIf(Range("E2:AT820"), "0")
Blad4.Cells(2, 1) = nrGaps

But this count the number of zero. Can somebody help?
You could try something like this.
If you're looking down columns run it this code as it is. For looking along rows leave out the red bit.
Rich (BB code):
Sub count_groups_of_zeros()
Dim c, q As Long, r As Long, s As Long
For Each c In Range("E2:AT820").Value
    If c = 0 Then
        r = r + 1
        If q = 0 Then
            q = 1
            s = s + 1
        End If
    Else
        q = 0
    End If
Next c
MsgBox r & " zeros in " & s & " groups"
End Sub
 
Upvote 0
Thank you so much!! It worked!!

You could try something like this.
If you're looking down columns run it this code as it is. For looking along rows leave out the red bit.
Rich (BB code):
Sub count_groups_of_zeros()
Dim c, q As Long, r As Long, s As Long
For Each c In Range("E2:AT820").Value
    If c = 0 Then
        r = r + 1
        If q = 0 Then
            q = 1
            s = s + 1
        End If
    Else
        q = 0
    End If
Next c
MsgBox r & " zeros in " & s & " groups"
End Sub
 
Upvote 0

Forum statistics

Threads
1,226,812
Messages
6,193,118
Members
453,777
Latest member
Miceal Powell

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