Count the Number of Gaps Between Numbers in a Row

dskexcel

New Member
Joined
Mar 4, 2015
Messages
48
Hi - I need to count the number of times a single or multiple set of columns contain "0" before the next column, which would contain a number. Probably not doing great describing it, but in the below example, I would want the formula to bring a result of 3:

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]0[/TD]
[TD]0[/TD]
[TD]12[/TD]
[TD]12[/TD]
[TD]56[/TD]
[TD]35[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]656[/TD]
[TD]654[/TD]
[TD]653[/TD]
[TD]32[/TD]
[TD]32[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]65[/TD]
[TD]0[/TD]
[TD]45[/TD]
[TD]45[/TD]
[/TR]
</tbody>[/TABLE]

So, I need to count the number of sets or number of single 0's within the range. In this case, there are 3 (in red). I also only need to count the sets of 0 after the first >0 cell in the range. So in the example above, I need to count the sets after the 3rd column or the cell with the # 12.

If i could avoid using an array that would be ideal, as I need to calculate this for 20K rows.

Thanks!
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
One idea I have is "if cell a>0 AND a+b=a, then count it." Any way to do this for the whole range?
 
Last edited:
Upvote 0
Hi,

my fun is to type some letters in nodepad:

Code:
sub iFen()
j=1
do until cells(1,j) > 0
j=j+1
loop
set rng = range(cells(1,j), cells(1, columns.count).end(xltoleft))
rng.replace 0, "a"
msgbox "number of 0 blocks: " & rng.specialcells(2,1).areas.count
rng.replace  "a", 0
end sub

Some issues for debugging are likely.

regards
 
Upvote 0
Control+shift+enter, not just enter:

=SUM(IF(FREQUENCY(IF(INDEX(A2:U2,MATCH(TRUE,A2:U2>0,0)):U2=0,COLUMN(INDEX(A2:U2,MATCH(TRUE,A2:U2>0,0)):U2)),IF(1-(INDEX(A2:U2,MATCH(TRUE,A2:U2>0,0)):U2=0),COLUMN(INDEX(A2:U2,MATCH(TRUE,A2:U2>0,0)):U2))),1))
 
Upvote 0
Hi,

It's an array one....so Ctrl+Shift+Enter NOT just Enter

For non-zero sets

=SUM(IFERROR(FREQUENCY(IF(A1:U1<>0,COLUMN(A1:U1)),IF(A1:U1<>0,0,COLUMN(A1:U1)))^0,0))

For zero sets

=IF(A1=0,SUM(IFERROR(FREQUENCY(IF(A1:U1=0,COLUMN(A1:U1)),IF(A1:U1=0,0,COLUMN(A1:U1)))^0,0))-1,SUM(IFERROR(FREQUENCY(IF(A1:U1=0,COLUMN(A1:U1)),IF(A1:U1=0,0,COLUMN(A1:U1)))^0,0)))
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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