Counting Consecutive Zeroes

ststern45

Well-known Member
Joined
Sep 17, 2005
Messages
976
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Hi everyone,

I have this formula that will count how many consecutive zeroes appear at the bottom of a range:

=MAX((U20:U219<>"")*(ROW(U20:U219)))-MAX((U20:U219<>0)*(U20:U219<>"")*(ROW(U20:U219)))

How do I change the formula where it counts from the beginning of a range. For example,

U20 = 0
U21 = 0
U22 = 0
U23 = 1 (Note: can be any number other than 0 (zero)

So the correct calculation would be 3 (3 consecutive zeroes)

Thanks in advance!!
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Hi ststern,

I think I might be able to help. I see in your example that your three consecutive 0's are for U20 to U22. What is your counting plan if for example you have:

U20 = 0
U21 = 0
U22 = 0
U23 = 1
U24 = 0
U25 = 0
U26 = 7

We have two sets of consecutive 0's. A set of 3 and a set of 2. Also, can you specify the range: is it fixed, variable, where it begins (A1 or somewhere else)...

Regards,
Peatawn
 
Upvote 0
If U20 is other than a zero the result would be 0. I just want to count how many consecutive zeroes begin at cell U20 going downward. One it reaches any value other than a 0 it would stop. So in you example the result would be 3 since there are 3 consecutive zeroes starting a cell U20
 
Upvote 0
The range is always 20:219 for example U20:U219, V20:V219, etc.

Here is another formula I found that calculated from the bottom:

=COUNTIF(INDEX(U20:U219,IF(COUNTIF(U20:U219,">0"),MATCH(2,1/(U20:U219>0)),1)):INDEX(U20:U219,MATCH(2,1/(U20:U219<>""))),0)
 
Upvote 0
I just tried this on my end and works perfectly. Not that I've tested hundreds of combinations, but you might want to try this:

=MATCH(NOT(0)+0,U21:U219,0)-1

Let me know if it works! :)
 
Last edited:
Upvote 0
Quite a challenge. I love that. Is there a maximum number thatcould break the sequence of 0's. I mean, could it be, 0, 0, 0, 102579... or is there a max value for the number that breaks the sequence?
 
Upvote 0
In V20 enter first formula. In V21 enter second formula and pull down.

=IF(U20=0,1,0)

=IF(U21=0,1+V20,0)

Not sure if this is the kind of read out you want or can live with.

Regards,
Howard
 
Upvote 0

Forum statistics

Threads
1,225,327
Messages
6,184,296
Members
453,227
Latest member
Slainte

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