Explanation

The key to this formula is the array or TRUE and FALSE values constructed with this expression:

LEFT(code,1)<>"N"

Here, each value in the named range “code” is evaluated with the logical test “first letter is not N”. The result is an array or TRUE and FALSE values like this:

{FALSE;FALSE;FALSE;FALSE;TRUE;FALSE;FALSE;TRUE}

This array is fed into the MATCH function as the lookup array. The lookup value is TRUE, and match type is set to zero to force an exact match. The MATCH function returns the position of the first value that does not begin with the letter “N” (Z09876), which is 5.

INDEX and MATCH

To retrieve a value associated with the position returned by MATCH, you can add the INDEX function. In example shown, the formula in F6 is:

{=INDEX(value,MATCH(TRUE,LEFT(code,1)<>"N",0))}

Note we are using the same MATCH formula above to provide a row number to INDEX, with the array set to the named range “value”. As before, MATCH returns 5. INDEX then returns the value at that position, -23.

As before, this is an array formula and must be entered with control + shift + enter.

Explanation

Working from the inside out, the ISERROR function returns TRUE when a value is a recognized error, and FALSE if not.

When given a range of cells (an array of cells) ISERROR function will return an array of TRUE/FALSE results. In the example, this resulting array looks like this:

{FALSE;FALSE;FALSE;FALSE;FALSE;TRUE;FALSE;FALSE}

Note that the 6th value (which corresponds to the 6th cell in the range) is TRUE, since cell B9 contains #N/A.

The MATCH function is configured to match TRUE in exact match mode. It finds the first TRUE in the array created by ISERROR and returns the position. If no match is found, the MATCH function itself returns #N/A.

Finding the first NA error

The formula above will match any error. If you want to match the first #N/A error, just substitute ISNA for ISERROR:

{=MATCH(TRUE,ISNA(B4:B11),0)}