* Formula: =LOOKUP(2,1/(1-ISBLANK(A1:A65535)),A1:A65535)
* This formula uses LOOKUP in its vector syntax form, with the lookup value as the first parameter, the lookup vector as second, and the result vector as the last parameter.
* The most interesting part of this formula is the lookup vector (the 2nd parameter). The formula element
1/(1-ISBLANK(A1:A65535))
in this example returns the following array
{1;1;1;1;1;1;1;#DIV/0!;1;1;#DIV/0!;#DIV/0!;
;#DIV/0!}
that is, the ISBLANK function returns an array of TRUE (blank cell) or FALSE (non-blank cell) values. Subtracting this from 1 converts the array to an array of 0 (blank) or 1 (non-blank) values. Dividing 1 by this array then returns an array of #DIV/0 (blank) or 1 (non-blank) values.
* The LOOKUP searches for the value 2′ within the array (which now consists only of 1′ and #DIV/0 values). The LOOKUP will not find this value, so it matches the last value that is less than or equal to lookup value. This is the last 1′ within the range which represents the last filled cell.
* Restriction: you cant use a complete column reference such as A:A for this type of formula.
* This type of formula can be used for a lot of similar problems using the second parameter to create a lookup vector consisting of either 1′ or #DIV/0′ errors by setting the Boolean expression accordingly. I personally saw this usage first in a posting from Aladin Akyurek.
Bookmarks