There are plenty of formula-based solutions for finding the last non-empty cell value from a column, row or continuous range in Excel, for example, for columns the most popular are =LOOKUP(2,1/(A:A<>""),A:A)
and =LOOKUP(2,1/(NOT(ISBLANK(A:A))),A:A)
. This is nice, but it only works for continuous ranges. Sometimes, however, you need to do the same for a list of disconnected cells or ranges of cells instead of a single continuous range. So, if there was a hypothetical function FINDLASTNONBLANK()
, its call would look like this:
For an arbitrarily long list of single cells
=FINDLASTNONBLANK(A1, D1, F1)
=FINDLASTNONBLANK(A1, D1, F1, X1)
For an arbitrarily long list of ranges
=FINDLASTNONBLANK(A1:A4, A10:A15)
=FINDLASTNONBLANK(A1:A4, A10:A15, A20:A25)
Obviously, there is no such ready-made formula, so I am wondering if there is a way to concoct a formula-based solution for that. No VBA UDFs.
So far I was thinking in the following direction: if I could write a formulation for joining disconnected cells/ranges into one range/array, then perhaps I could use the classic =LOOKUP(2,1/(A:A<>""),A:A)
hack, something like this (assuming hypothetical formula JOINRANGES()
or a hypothetical aggregation syntax {,}
):
=LOOKUP(2,1/(JOINRANGES(A1:A4,A10:A15)<>""),JOINRANGES(A1:A4,A10:A15))
=LOOKUP(2,1/({A1:A4,A10:A15}<>""),{A1:A4,A10:A15})
So maybe there is a syntax in Excel to specify an array from a list of disjoint cells/ranges/arrays that I am not aware of? If there is, it should be backwards-compatible with at least Excel 2007.
I would be fine with the solution being limited to 1-dimensional data sources (row only, column only), does not have to work on 2-dimensional matrix. In fact, I would be fine with a solution only working on the disjoint data from the same row, not even a column.