WorkbookLogic
FunctionDynamic ArrayadvancedXMATCHROWIF

XMATCH Function

By WorkbookLogic

The Excel XMATCH function returns an item's one-based position inside a row or column, with exact matching by default and optional reverse or wildcard searches.

ExcelLast reviewed Sep 11, 2026
xmatch-function-v1.0.0.xlsx
Excel XMATCH Function
XMATCH returns an item's one-based position inside a lookup array.
Lookup list, editableExamples
ItemStatusNoteList positionExampleFormula syntaxPosition
MercuryOpenFirst1Exact match=XMATCH("Mars",A12:A19)4
VenusClosedSecond2Second item=XMATCH("Jupiter",A12:A19)5
EarthPendingThird3Last Open status=XMATCH("Open",B12:B19,0,-1)8
MarsOpenFourth4Wildcard contains=XMATCH("*turn*",A12:A19,2)6
JupiterClosedFifth5
SaturnPendingSixth6
UranusClosedSeventh7
NeptuneOpenEighth8
Reliability checks
Mars is fourth within the bounded lookup arrayOK
Reverse search finds Open in the eighth list positionOK

Overview

The Excel XMATCH function looks for a value in one row or column and returns its position within that lookup array. It uses exact matching by default and can search from either end, match wildcards, or apply approximate and binary search modes.

Quick reference

Syntax: =XMATCH(lookup_value, lookup_array, [match_mode], [search_mode])

Returns: The one-based numeric position of the matched item within lookup_array. (number)

Arguments:

  • lookup_value (required) — The value to locate.
  • lookup_array (required) — The row or column searched for the value.
  • match_mode (optional) — Controls exact, approximate, or wildcard matching; exact is the default.
  • search_mode (optional) — Controls first-to-last, last-to-first, or binary search behavior.

The lookup value and one-dimensional lookup array are required. Optional match and search modes control approximate or wildcard matching and search direction; exact matching is the default.

Common uses

  • Find a row or column position for INDEX.
  • Locate a header in a changing report structure.
  • Find the final occurrence of a repeated status or identifier.
  • Test wildcard position matching in text lists.

Calculations

XMATCH compares lookup_value with the items in lookup_array and returns the matching item's one-based position. If Mars is the fourth item in A12:A19, XMATCH returns 4; it does not return worksheet row 15.

The default search is exact and moves from first to last. Setting search_mode to -1 reverses the search, which is useful when duplicate values exist. Wildcard matching uses match_mode=2.

If nothing matches, XMATCH returns #N/A. Binary search modes are available for deliberately sorted arrays, but they should not be used on unsorted data.

Function behavior

Situation

Behavior

Exact match

Default when match_mode is omitted.

Position basis

One-based relative position inside lookup_array.

Duplicate values

First occurrence by default; final occurrence with search_mode=-1.

Wildcards

match_mode=2 enables *, ?, and ~.

No match

Returns #N/A.

Lookup shape

Designed for one row or one column.

Binary search

Requires correctly sorted data.

Common errors

Treating the result as a worksheet row

What happens:
A result such as 4 is interpreted as row 4, even when the lookup array starts elsewhere.

Better approach:
Read the result as the item's position within the supplied array.

Passing a two-dimensional lookup range

What happens:
The intended position is ambiguous and the formula may fail.

Better approach:
Supply one bounded row or column.

Using binary search on unsorted data

What happens:
The returned position may be incorrect.

Better approach:
Keep the default search unless the array is maintained in the required order.

Example

Example 1 — Exact Position

=XMATCH("Mars",A12:A19)

On XMATCH Example, Mars is fourth in the bounded lookup array, so the result is 4.

Example 2 — Another Cell Range Lookup

=XMATCH("Jupiter",A12:A19)

Jupiter is the fifth list item, so the result is 5.

Example 3 — Last Matching Status

=XMATCH("Open",B12:B19,0,-1)

The status Open occurs several times. Searching from the end returns position 8, the final occurrence in the lookup array.

Example workbook

The workbook contains XMATCH Example and Notes. The main sheet provides an editable eight-item list, four live XMATCH examples, and a visible helper position generated with ROW. Two IF checks verify the exact and reverse-search results, and both display OK.

Key takeaway

XMATCH returns a position inside the lookup array, not an associated value or an absolute worksheet row.