The XMATCH function takes four arguments: lookup_value, lookup_array, match_mode, and search_mode. Lookup_value is the value to look for, and lookup_array is the range or array to search. Both arguments are required. The match_mode argument controls what kind of match is performed (exact, next smallest, next largest, or wildcard), see match_mode below for details. Finally, search_mode controls the search direction - whether XMATCH should start at the beginning of the array, at the end of the array, or if XMATCH should perform a binary search. See search_mode below for details. XMATCH only supports one-dimensional arrays or ranges, either vertical and horizontal. However, you can use XMATCH to locate values in a two-dimensional range or table by giving XMATCH a single column or row that contains the lookup value (basic INDEX and MATCH example). You can also use MATCH twice in a single formula to find a matching row and column at the same time (INDEX and MATCH example).

XMATCH vs. MATCH

The XMATCH function works just like MATCH function, but with more capability and flexibility. In some cases, XMATCH can be a drop-in replacement for the MATCH function. For example, for exact matches, the syntax is identical: However, for approximate matches, the behavior is different when match type is set to 1: In addition, XMATCH allows -1 for match type, which is not available with MATCH: Note: the MATCH function does not offer the search mode argument at all.

Match mode

The third argument for XMATCH is match_mode. This is an optional argument that controls match behavior as follows:

Search mode

The fourth argument for XMATCH is search_mode. This is an optional argument that controls search behavior as follows: Binary searches are very fast, but take care data is sorted as required. If data is not sorted properly, a binary search can return invalid results that look perfectly normal.

Exact match

In the example shown, XMATCH is used to retrieve the position of “Mars” in a list of planets in the range B6:B14. The formula in G6 is: Notice XMATCH defaults to an exact match. If “Mars” G5 was misspelled “Marz”, XMATCH would return #N/A.

Match mode behavior

The example below illustrates match mode behavior with a lookup value of 3.1 in E4, and lookup values in B5:B11.

INDEX and XMATCH

XMATCH can be used just like MATCH with the INDEX function. To retrieve the diameter of Mars based on the original example above, the formula is:

XMATCH with wildcard

When match_mode is set to 2, XMATCH can perform a match using wildcards. In the example shown below, the formula in E5 is: This is equivalent to:

XMATCH locates the first code that begins with “pq” and returns 6, since PQR-121 appears in row 6 of the range B5:B13. Notice XMATCH is not case-sensitive.

Case-sensitive match

The MATCH function is not case-sensitive. However, MATCH can be configured to perform a case-sensitive match when combined with the EXACT function in a generic formula like this: The EXACT function compares every value in array with the lookup_value in a case-sensitive manner. This formula is explained in an INDEX and MATCH example here. The example uses the MATCH function, but XMATCH can be substituted with the same result.

Notes

Dave Bruns

Hi - I’m Dave Bruns, and I run Exceljet with my wife, Lisa. Our goal is to help you work faster in Excel. We create short videos, and clear examples of formulas, functions, pivot tables, conditional formatting, and charts.

Excel XMATCH function - 58