INDEX with array formula is giving different results than INDIRECT with ADDRESS when used by COUNTA

The following sheet illustrates the problem:

enter image description here

I want to know if there is any non-blank cell in a range, but once the sheet is autogenerated, I can't refer to this range directly (B3:B5). It is relative to some column.

Due to performance reasons, I want to use the INDEX function instead of INDIRECT, but when I pass the INDEX result to COUNTA, I am getting 3 non-blank cells when I just have 2.

Why COUNTA(INDEX($1:$24, {3;4;5}, 2)) gives a different result than COUNTA(INDIRECT(ADDRESS(3, 2) & ":" & ADDRESS(5, 2)))?


That is because INDEX returns an array to the counta:

enter image description here

and the blank cell is 0 in the array, where as Indirect returns a range:

enter image description here

In the array the 0 counts as 1 but since the second refers to a range it sees B4 as empty and does not count it.


We can still use INDEX and return an address to the counta:

=COUNTA(INDEX($1:$24, 3, 2):INDEX($1:$24, 5, 2))

This has the luxury of not being volatile and still seeing B4 as empty.

enter image description here