Counting cells with number

Keala

New Member
Joined
Jul 9, 2018
Messages
37
I have issue in count cells which I hope you can suggest a solution for.

I have column with a mix of 0s and value >0. So I need to count number of zeros in between each number>0 and state it on the next column.
It looks like this and what I want to achieve:
1
0
0
0
0
12 count= 4
0
0
0
3 count=3
0
0
0
0
0
0
55 count=6
...

The number of zeros is different all the time, sometimes it is only 3 zeros then a number or sometime it is 55 zeros then a number. I could do this manually with count function but since it is more then 300000 rows it will be quite demanding.

All suggestions are appreciated, maybe a macro is not neccessary and a work sheet solution would do it?
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
try this


Book1
AB
11
20 
30
40
50
6124
70
80
90
1033
110
120
130
140
150
160
17556
Sheet7
Cell Formulas
RangeFormula
B2=IF(A2=0,"",COUNTIF($A$1:A2,0)-SUM($B$1:B1))
 
Upvote 0
Thank you Alan for the suggestion, but unfortunately I get alert code:

"There's a problem with this formula.
Not trying to type a formula?
...
"

Just to make sure I'm clear, the numbers and position below is just as example. The column which this need to be applied on is about 30000 rows and the cell number of zeros and number>0 is undefined.
 
Upvote 0
try this


Book1
AB
11
20 
30
40
50
6124
70
80
90
1033
110
120
130
140
150
160
17556
Sheet7
Cell Formulas
RangeFormula
B2=IF(A2=0,"",COUNTIF($A$1:A2,0)-SUM($B$1:B1))

have you copied the formula above to Cell B2 directly? it should work.
 
Upvote 0
It works fine for me.
If you set up the example like Alan shows, does it work on that?
If it does work on that example, but not on your data, then you are probably either making a typo or not quite applying it correctly to your situation.
(Also, your number are entered as numbers, and not text, right)?
 
Upvote 0
Yes, I have both copied and typed it my self. None work. I'm using Excel 2016 and have comma as separator with two digit decimal numbers, if that matters?
 
Upvote 0
how about?

Code:
=IF(A2=0,"",COUNTIF($A$1[COLOR="#FF0000"];[/COLOR]A2,0)-SUM($B$1[COLOR="#FF0000"];[/COLOR]B1))
 
Upvote 0
Unfortunately it does not work for me on the exactly same setup as the example either.
 
Upvote 0
The output is the same, it highlight ||0,"",countif|| part of the command. So I did some tests and this =IF(A3=0;"";COUNTIF($A$1:A3;0)-SUM($B$1:B2)) does not pop a alert code but it does not fill any number either. Just a green arrow at the upper left corner on each cell?
 
Upvote 0
do the 2 formula below work for you?


Book1
AB
11
22
33
4
562
Sheet10
Cell Formulas
RangeFormula
A5=SUM(A1:A3)
B5=COUNTIF(A1:A3,">"&1)
 
Upvote 0

Forum statistics

Threads
1,224,918
Messages
6,181,743
Members
453,064
Latest member
robatthe2A

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