XL: Returning the First or Last Match in an ArrayID: Q104224
|
In Microsoft Excel you can use the LOOKUP() function to search for a
value within an array of sorted data and return the corresponding
value contained in that position within another array. If the lookup
value is repeated within the array, it will return the last match
encountered. This behavior is true for the VLOOKUP(), HLOOKUP(), and
LOOKUP() functions.
To find the first value instead of the last value in an array, you can
use the INDEX() and MATCH() functions.
The example below contrasts the results you get when you use the
LOOKUP() function with the results you get when you use the INDEX()
and MATCH() functions:
A1: 1 B1: Red C1: =LOOKUP(1,A1:A4,B1:B4)
A2: 1 B2: Blue C2: =INDEX(A1:B4,MATCH(1,A1:A4,0),2)
A3: 2 B3: Orange
A4: 3 B4: Yellow
"Function Reference," version 4.0, pages 221, 236, 264, 267, 450
"Function Reference," version 3.0, pages 123, 128, 145, 148, 246
Additional query words: howto
Keywords : kbdta xlformula
Version : WINDOWS:2.0,3.0,4.0,5.0,7.0,97; MACINTOSH:2.0,3.0,4.0,5.0
Platform : MACINTOSH WINDOWS
Issue type : kbinfo
Last Reviewed: April 7, 1999