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:

001212563500656654653323200006504545

<tbody>
</tbody>

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

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
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
Give this a try, $V$2 should be left blank:

Excel Workbook
ABCDEFGHIJKLMNOPQRSTUVW
1
20012050003022120221120005
Sheet1
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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