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?
 
Try this:

Assuming the range and result are all in the active sheet.
Not sure what
Blad4
is.

Code:
Sub Count_Me()
'Modified 5/31/18 4:55 AM EDT
Application.ScreenUpdating = False
Dim ans As Long
ans = 0
Dim c As Range
    For Each c In Range("E2:AT820")
        If c.Value = "0" Then ans = ans + 1
    Next
Cells(2, 1).Value = ans
Application.ScreenUpdating = True
End Sub
 
Upvote 0
I'm sorry, blad4 means sheet4

Try this:

Assuming the range and result are all in the active sheet.
Not sure what
Blad4
is.

Code:
Sub Count_Me()
'Modified 5/31/18 4:55 AM EDT
Application.ScreenUpdating = False
Dim ans As Long
ans = 0
Dim c As Range
    For Each c In Range("E2:AT820")
        If c.Value = "0" Then ans = ans + 1
    Next
Cells(2, 1).Value = ans
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thanks! The code works, but is still counts the total of cells with the value of zero. But I need to count the total ranges.

For example:
1 1 1 0 0 1 0 The total amount of zeros is 3 but the total ranges with zeros is 2.

I don't know how to do that
 
Upvote 0
Is the range we are searching on sheet4

If not I need both sheet names.

Like this Sheet:

"Master"
"Four"
 
Upvote 0
I'm not sure now what your wanting.

You said search the range for "0"

I do not understand your example
 
Upvote 0
Are you saying if one cell has the value "000145678"
The count for that cell would be 3
 
Upvote 0
I'm making a calendar to allocate cottages to certain reservations. Now, I need to reduce the amount of gaps in this calendar, but first i need to count them.
Is all on the same sheet
 
Upvote 0
Not sure what Gaps are.
When you said "0" did you mean "0" or did you mean empty?

I think you may want to explain your entire Goal.
How would finding the number of cells with "0" help you remove Gaps
What is a Gap?
 
Last edited:
Upvote 0
The calendar contains on the top line the dates, on the left the number of a cottage. And within it is filled with the number of the reservation. If a cottage is empty on that date, it gets a 0 in the cell. I need to count the total number of zeros, but if there is a serie of zeros the gap is still counted as 1.
I hope this makes any sense ;)
 
Upvote 0

Forum statistics

Threads
1,226,775
Messages
6,192,932
Members
453,767
Latest member
922aloose

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