Count Blanks in dynamic range

mgirvin

Well-known Member
Joined
Dec 15, 2005
Messages
1,236
Office Version
  1. 365
Platform
  1. Windows
Dear Smartest Excelers Around,

I want to count blanks in a horizontal range (all in one row) that will change (dynamic range). The values in the range could be numbers or words. Some values may be added to the end, but there may still be some empty cells to the right of the last value. My goal is to count blanks in the range up to the last entered value, but no beyond that. As an example:

A6 = 2
B6 = empty cell
C6 = 2
D6 = empty cell
E6 = tt
F6 = empty cell

The range for the count blanks would be A6:E6. F6 is not included because the last entered value is in cell E6.

The answer (count blanks in dynamic range) should be 2.

I have got these 3 formulas to work, but it seems that there must be a better (shorter, faster calculating, more elegant) formula than these:

=COUNTBLANK(OFFSET(A6,,,,MATCH(9.9E+307,MATCH(A6:F6,A6:F6)+TRANSPOSE(ROW(INDIRECT(""1:""&COLUMNS(A6:F6)))))))

=COUNTBLANK(OFFSET(A6,,,,MATCH(9.9E+307,MATCH(A6:F6,A6:F6)+{1,2,3,4,5,6})))

=COUNTBLANK(A6:INDEX(A6:F6,MATCH(9.9E+307,MATCH(A6:F6,A6:F6)+TRANSPOSE(ROW(INDIRECT(""1:""&COLUMNS(A6:F6)))))))

Any ideas?

P.S. The trouble I was having with creating a formula was that all the blanks became zeros when I started analyzing it with MATCH and other functions...
 
Matty,

Thanks for taking the time to help me. Yes, you are right about Domenic, I have been getting EXCELlent help from him for years!!
 
Upvote 0

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Assuming that the count must be done with COUNTBLANK (which does not skip formula blanks)...

Control+shift+enter, not just enter...

One of:

=COUNTBLANK(OFFSET(A6,0,0,,MATCH(2,1/(6:6<>""))-MIN(COLUMN(A6))))

=COUNTBLANK(A6:INDEX(6:6,MATCH(2,1/(6:6<>""))))
 
Upvote 0
Wow, these are some great formulas clean and precise. If I wanted this to turn around and count blanks down rows instead what would need to change?


=COUNTIF(INDEX(A6:F6,MATCH(TRUE,A6:F6<>"",0)):INDEX(A6:F6,MATCH(2,1/(A6:F6<>""))),"")

I tried

=countif(index(F6:F12,,MATCH(TRUE,F6:F12<>"",0)):INDEX(F6:F12,,MATCH(2,1/(F6:F12<>"")))."") <Ctrl Shift Enter> and got a REF error.

I thought by changing the index to look at column versus row that would work...
 
Upvote 0
krn6264,

Try:

For counting blanks between the first cell and the last cell that contains a value, try:

=COUNTIF(F6:INDEX(F6:F12,MATCH(2,1/(F6:F12<>""))),"")
or
=COUNTBLANK(F6:INDEX(F6:F12,MATCH(2,1/(F6:F12<>""))))


For counting blanks between the first cell that contains a value and the last cell that contains a value, try:

=COUNTIF(INDEX(F6:F12,MATCH(TRUE,F6:F12<>"",0)):INDEX(F6:F12,MATCH(2,1/(F6:F12<>""))),"")
or
=COUNTBLANK(INDEX(F6:F12,MATCH(TRUE,F6:F12<>"",0)):INDEX(F6:F12,MATCH(2,1/(F6:F12<>""))))

Enter each formula with the key strokes Ctrl + Shift + Enter.
 
Upvote 0
Thanks Mike

I used the first countif and extended out my range to worst case. Counting blanks just great. Thanks so much for the expertise.
 
Upvote 0
Matty and Domenic provided the expertise!

By The Way, it looks like your original formula was correct except for the dot between the two COUNTIF arguments.
 
Upvote 0
ha, didn't even notice that. Thanks to Domenic, Matty, and Mike (for presenting question so eloquently for me).

Special thanks to Mike for all the great videos on his YouTube channel. I have learned COUNT less things from him.
 
Upvote 0
Assuming that the count must be done with COUNTBLANK (which does not skip formula blanks)...

Control+shift+enter, not just enter...

One of:

=COUNTBLANK(OFFSET(A6,0,0,,MATCH(2,1/(6:6<>""))-MIN(COLUMN(A6))))

=COUNTBLANK(A6:INDEX(6:6,MATCH(2,1/(6:6<>""))))


you are amazing Aladin
 
Upvote 0

Forum statistics

Threads
1,214,631
Messages
6,120,640
Members
448,974
Latest member
DumbFinanceBro

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