Table of Contents
Excel’s XMATCH returns the position of a match within a single row or column. To retrieve a value from another column, pass that position to INDEX. For example, you can find an employee’s name in column D and return their department from column B without rearranging the sheet.
Find the position of an exact match
=XMATCH(lookup_value, lookup_array, [match_mode], [search_mode])
With names in D2:D100, this formula finds the first occurrence of Kristen Tate. If the name is in D5, the result is 4 because the range starts at D2.
=XMATCH("Kristen Tate", D2:D100)
Find the closest value below a limit or the last duplicate
The match mode determines what counts as a match. Use 0 for exact matching (the default), -1 for the exact or next smaller value, 1 for the exact or next larger value, or 2 for wildcards. With numeric salaries in H2:H100, this returns the position of the highest salary at or below 75,000.
=XMATCH(75000, H2:H100, -1)
For duplicates, change the fourth argument. A search mode of -1 searches from the end, so the example below returns the last exact match in the range. It finds the newest record only if newer entries appear later in the range.
=XMATCH("John Smith", D2:D100, 0, -1)
Use the default search mode for ordinary unsorted ranges. The binary search modes require the lookup range to be sorted in the matching order: ascending for 2 or descending for -2.
Return a value from another column with INDEX
Use matching start and end rows for the search and return ranges. In this example, INDEX returns the value in column B from the same row where XMATCH finds the name in column D.
=INDEX(B2:B100, XMATCH("Kristen Tate", D2:D100))
For a two-condition example, suppose column A contains employee IDs, B contains departments, and H contains salaries. This Microsoft 365 formula finds the largest ID in Sales, looks up that ID within Sales, and returns the corresponding salary. It displays “No Sales records” when the department is absent.
=IF(COUNTIF(B2:B100,"Sales")=0,"No Sales records",INDEX(H2:H100,XMATCH(1,(B2:B100="Sales")*(A2:A100=MAXIFS(A2:A100,B2:B100,"Sales")))))
For one straightforward lookup that returns a value directly, consider XLOOKUP. When sharing a workbook with users of older Excel versions that lack XMATCH, use MATCH with an explicit 0 for an exact match.
Reader Comments 0
Sign in with email or Google to join the discussion.