Explanation
In this example the named range “range1” refers to cells B5:B8, and the named range “range2” refers to D5:D7. We are using named ranges for convenience and readability only; the formula works fine with regular cell references as well.
The core of this formula is INDEX and MATCH. The INDEX function retrieves a value from range2 that represents the first value in range2 that is found in range1. The INDEX function requires an index (row number) and we generate this value using the MATCH function, which is set to match the value TRUE in this portion of the formula:
MATCH(TRUE,COUNTIF(range1,range2)>0,0)
Here, the match value is TRUE, and the lookup array is created with COUNTIF here:
COUNTIF(range1,range2)>0
COUNTIF returns a count of the range2 values that appear in range1. Because range2 contains multiple values, COUNTIF will return multiple results that look like this:
{0;0;1}
We use “>0” to force all results to either TRUE or FALSE:
{FALSE;FALSE;TRUE}
Then MATCH does its thing and returns the position of the first TRUE (if any) that appears, in this case, the number 3.
Finally, INDEX returns the value at that position, “Red”.
Explanation
When given a single cell reference, the ROW function returns the row number for that reference. However, when given a range that contains multiple rows, the ROW function will return an array that contains all row numbers for the range. In the example shown the array looks like this:
{5;6;7;8;9;10}
If you want only the first row number, you can use the MIN function to extract just the first row number, which will be the lowest number in the array.
Simple version
Entered in a single cell, the ROW function will display only the first row number, even though it returns an array. This means, in practice, you can often just use the ROW function alone:
=ROW(rng)
However, inside formulas more complex formulas, it’s sometimes necessary to make sure you are dealing with only one item, and not an array. In that case, you’ll want to use MIN to pull out just the first item.
Index version
Since ROW (range) actually returns an array of every row number in the range, you can also use INDEX to fetch the first item:
=ROW(INDEX(data,1,1))
Not tested, but this may be slightly faster than the MIN(ROW) formula in very large ranges.