How to Xmatch Function in Excel

Learn multiple Excel methods to xmatch function with step-by-step examples and practical applications.

excelformulaspreadsheettutorial
13 min read • Last updated: 7/2/2025

How to Xmatch Function in Excel

Why This Task Matters in Excel

Modern workbooks rarely live in isolation. They usually pull data from multiple tables, consolidate information from different sheets, and drive interactive dashboards. In all these cases you need a reliable way to find the exact position of an item inside a list or table so that other formulas or lookups can feed off that position. This is exactly what XMATCH was designed to do, and it does so more flexibly and faster than its predecessors.

Imagine a sales analyst who receives updated product codes every Monday. A dashboard may need to find where the code appears in the updated list so that the correct sales numbers populate downstream. A human-resources specialist might have thousands of employee IDs spread across departments in separate sheets; finding the row number of a specific ID quickly is critical for payroll calculations. A supply-chain planner might need to locate the column position of the first late shipment in a timeline to trigger escalation. The common thread across these scenarios is “tell me where this item is so I can retrieve or manipulate related data.”

Before Office 365, analysts leaned on MATCH in combination with INDEX, or VLOOKUP for approximate matches. Those methods still work, but they have important drawbacks: MATCH could not search from the bottom, it handled approximate searches awkwardly, and it struggled with modern dynamic arrays. XMATCH fixes all of these issues. It:

  • Works natively with dynamic arrays, so one formula can spill multiple results.
  • Searches from first-to-last or last-to-first with the same syntax.
  • Supports exact matches, wildcard matches, and approximate matches that sort in ascending or descending order.
  • Handles vertical and horizontal lookups identically, so you no longer need separate techniques for rows vs columns.
  • Is noticeably faster on very large datasets because Microsoft rewritten it for the new calculation engine.

Failing to master XMATCH can cost you real time. You may end up writing long combinations of INDEX & MATCH or fragile VLOOKUP formulas, and you miss out on the performance improvements and clarity that XMATCH brings. Because XMATCH returns a relative position instead of a value, it also cements your understanding of lookup-position-retrieve workflows—skills that cascade into INDEX, XLOOKUP, FILTER, TAKE, CHOOSECOLS, and other modern functions. Learning XMATCH, therefore, is both a productivity boost today and a foundation for advanced Excel modeling tomorrow.

Best Excel Approach

The most straightforward method for position lookups in today’s Excel is XMATCH. It is optimized for speed, integrates seamlessly with dynamic arrays, and unifies multiple matching behaviors under a single argument set.

Syntax:

=XMATCH(lookup_value, lookup_array, [match_mode], [search_mode])
  1. lookup_value – the item you are trying to find (number, text, logical, date, or even a spill range).
  2. lookup_array – the one-dimensional range or array where Excel will search.
  3. [match_mode] – optional, controls exact, wildcard, or approximate matching.
    • 0 (default) exact match
    • -1 exact or next smaller
    • 1 exact or next larger
    • 2 wildcard match
  4. [search_mode] – optional, controls the search direction.
    • 1 (default) search first-to-last
    • -1 search last-to-first
    • 2 binary search ascending order
    • -2 binary search descending order

If you only need the index (row or column number) of a single exact match from top to bottom, you can omit both optional arguments:

=XMATCH("KT-201", [A2:A5000])

When you need backward searches, wildcard support, or approximate matches in sorted lists, XMATCH’s optional arguments save you from writing separate functions. For example, search from bottom up for the last entry of “Pending” in a status list:

=XMATCH("Pending", [D2:D1000], 0, -1)

You would only consider legacy MATCH when you are locked into an older Excel version without access to XMATCH. XLOOKUP can also replace XMATCH, but if you primarily want the position rather than the retrieved value, XMATCH keeps formulas shorter and easier to read. Prerequisites: Office 365 or Excel 2021 onward.

Parameters and Inputs

XMATCH expects a single-column or single-row lookup array. If you accidentally feed a two-dimensional range (for example [A2:C2]) XMATCH returns a #N/A error. Always confirm that the lookup_array collapses to one dimension.

  • Text vs numbers: Numbers stored as text cause mismatches. Apply the VALUE function or use Text to Columns to convert them.
  • Wildcards: When match_mode is 2, lookup_value can contain ? for a single character or * for multiple characters. Disable wildcards by forcing match_mode to 0.
  • Sorted lists: If you use binary search modes 2 or -2, the lookup_array must be sorted ascending or descending respectively. Failure triggers wrong positions without an obvious error, so adding data-validation prompts or conditional formatting to highlight unsorted areas is good practice.
  • Spill arrays as lookup_value: You can feed a dynamic spill range such as `=UNIQUE(`[B2:B100]). XMATCH will spill matching positions for every element. Ensure downstream formulas that consume the output are sized properly.
  • Case sensitivity: XMATCH is not case sensitive; use EXACT and FILTER inside a helper array for case-sensitive requirements.
  • Blank cells: Blanks are treated as empty strings. If you search for \"\", XMATCH returns the position of the first blank cell.
  • Error handling: Wrap XMATCH inside IFNA to trap missing items and deliver friendly messages.
  • Data preparation: Trim spaces, normalize date formats, and verify no hidden characters (especially when importing from external systems).

Step-by-Step Examples

Example 1: Basic Scenario – Find a Product Row

Suppose you manage an inventory list with product codes:

A (Product Code)B (Description)C (Qty)
P-001Widget Small43
P-002Widget Large16
P-003Bracket103
P-004Bolt258

You want cell E2 to contain the row number of product code typed in D2. Steps:

  1. Enter the code to search in D2, e.g., “P-003”.
  2. In E2, enter:
=XMATCH(D2, [A2:A100])
  1. Press Enter. Result: 3 (because P-003 is the third element in [A2:A100]).
  2. Combine with INDEX to pull the description automatically:
=INDEX([B2:B100], XMATCH(D2, [A2:A100]))

Now whenever a new code is typed in D2, both the row number and the description update instantly. This works because XMATCH returns a relative index that INDEX can use. Common variations:

  • Replace D2 with data-validation dropdown for safer inputs.
  • Wrap XMATCH with IFNA to catch missing codes:
    =IFNA(XMATCH(D2, [A2:A100]), "Not found")
    Troubleshooting tip: If XMATCH returns #N/A even though the code is visible, check for trailing spaces or mismatched data types.

Example 2: Real-World Application – Last Status Update in a Timeline

A project manager logs status updates across columns by week:

A (Task)B (1-Jan)C (8-Jan)D (15-Jan)E (22-Jan)
DesignOn TrackOn TrackAt RiskCompleted
BuildNot StartedIn ProgressIn Progress
Test

Goal: For each task, retrieve the most recent non-blank status. Steps:

  1. In row 2, F2 will compute the column position of the last entered status.
  2. Formula:
=XMATCH("*", [B2:E2], 2, -1)

Explanation:

  • lookup_value is a single asterisk inside quotes. Because match_mode 2 enables wildcards, “*” matches any text.
  • search_mode -1 tells XMATCH to start from the rightmost cell and move left.
  • The function returns 4 for task Design (because E2 is the fourth element in the lookup_array).
  1. Retrieve the actual status:
=INDEX([B2:E2], XMATCH("*", [B2:E2], 2, -1))
  1. Copy the formula down for all tasks. This pattern scales easily to dozens of weekly columns without helper columns.
    Business benefit: Managers see the latest status at a glance, dashboards refresh automatically, and there is no need to manually move or hide columns each week.
    Performance consideration: For 200 tasks across 52 weeks, this single formula pair calculates faster than array formulas that scan whole rows because search_mode -1 stops at the first match.

Example 3: Advanced Technique – Multi-Criteria Dynamic Spill

Assume a customer success team tracks subscription renewals. Columns:

| A (Cust ID) | B (Region) | C (Plan) | D (Renewal Date) | E (Monthly Revenue) |

The regional director wants a dynamic numbered list of all North-America customers on the “Enterprise” plan, sorted by earliest renewal. Steps:

  1. Create a spill range G2 with filtered IDs:
=FILTER(A2:E500, (B2:B500="North-America")*(C2:C500="Enterprise"))
  1. Sort by renewal date:
=SORT(FILTER(A2:E500, (B2:B500="North-America")*(C2:C500="Enterprise")), 4, 1)
  1. In H2, calculate the position of each customer ID inside the master unsorted list to feed other reports:
=XMATCH(G2#, A2:A500)

Because G2# represents a dynamic array of IDs, XMATCH returns a spilled column of positions matching each element. These positions feed into INDEX to grab related metrics from parallel tables. Edge cases:

  • If no customers fit the criteria, FILTER returns #CALC! error; wrap it with IFERROR to handle gracefully.
  • Changes in the source table automatically resize the spill and XMATCH output—no manual maintenance.
    Professional tip: When spilling large arrays, anchor output ranges at the bottom of the worksheet or convert to an Excel Table so that new data doesn’t overwrite downstream formulas.

Tips and Best Practices

  1. Always wrap unsupervised lookups with IFNA or IFERROR to transform user-facing sheets from cryptic #N/A messages to “Item not found” notes.
  2. Leverage Tables: Convert your source lists to Excel Tables (Ctrl+T). XMATCH will then reference structured names like Products[Code], making formulas self-documenting and automatically extending as new rows are added.
  3. Use search_mode -1 for efficiency when you know the desired match is likely near the bottom of the list—XMATCH stops at the first hit, cutting calculation time.
  4. Combine with INDEX or XLOOKUP thoughtfully: If you need the value immediately, XLOOKUP may replace both INDEX and XMATCH. Keep XMATCH for scenarios where the numeric position feeds other logic (for example, OFFSET, CHOOSECOLS, or TAKE).
  5. Document match_mode choices in adjacent comment cells so that future maintainers remember why wildcard or approximate search was chosen.
  6. Audit wildcards: When using match_mode 2, verify that your lookup_value really needs a wildcard. Unintended “*” inside imported data can create false positives.

Common Mistakes to Avoid

  1. Supplying a two-dimensional lookup_array. XMATCH demands a single row or column. Symptom: #N/A error even though the value exists. Fix: wrap with INDEX to coerce one dimension or select the correct range.
  2. Mismatched data types. Searching a text “123” in a numeric column fails. Recognize by testing `=ISTEXT(`range cell). Solution: convert text numbers with VALUE or multiply by 1.
  3. Overlooking sorting when using binary search modes 2 or -2. If the data isn’t sorted properly, XMATCH may return random positions without errors. Prevention: use SORT to pre-sort or stick to exact match modes.
  4. Forgetting to anchor ranges in copied formulas. When copying XMATCH across columns, row references may shift unintentionally. Lock ranges with $ (for example $A$2:$A$100) or use structured references in Tables.
  5. Using wildcards unintentionally. A lookup_value ending in * because of a user typo matches anything that starts with that string. Detect it by LEN and RIGHT checks, strip with SUBSTITUTE, or force exact matching.

Alternative Methods

Although XMATCH is the modern champion, there are other ways to find positions. Here’s how they compare:

MethodExcel VersionSyntax LengthDirection OptionsWildcardsSpeed on Large DataDynamic Arrays
MATCHAll versionsShortTop-down onlyYesGoodNeeds wrapper
INDEX+MATCHAll versionsMediumTop-downYesGoodManual spill
XLOOKUP (return column)365/2021Longer when returning positionTwo directionsYesGreatNative
FILTER+SEQUENCE365/2021LongerAny (post-processing)YesVery goodNative
VBA Application.MatchAnyCodeCustomCustomDependsNot formula

When to use MATCH: Legacy workbooks shared with users on Excel 2016 or earlier.
When to use XLOOKUP: You ultimately need the value, not just the position.
When to use FILTER+SEQUENCE: Building dynamic reports that need the row numbers of multiple records meeting complex criteria.
Migration strategy: Replace MATCH with XMATCH gradually by adding a helper column and validating that results stay the same, then swap dependent formulas.

FAQ

When should I use this approach?

Use XMATCH whenever you need the row or column index of a target item, particularly if you plan to feed that number into INDEX, OFFSET, TAKE, CHOOSECOLS, or dynamic spill operations. It excels in stock control lists, financial models, and dashboards that require frequent position lookups.

Can this work across multiple sheets?

Yes. Point lookup_array to another sheet such as Sheet2!A2:A100. Make sure both sheets remain open; closed external workbooks will break dynamic arrays until reopened. For three-dimensional lookups (same code across many identically structured sheets), consider stacking sheets with VSTACK first, then run XMATCH.

What are the limitations?

XMATCH is limited to one-dimensional arrays and is not case-sensitive. It cannot natively search on multiple criteria; you need to pre-combine criteria columns into a helper column or filter the list before searching. Approximate modes require sorted lists, and performance benefits diminish if the engine must coerce text numbers constantly.

How do I handle errors?

Wrap your formula: =IFNA(XMATCH(...), "Not found"). If you expect multiple potential error types (for example #VALUE! from wrong dimension inputs), nest IFERROR around IFNA or test with ISNUMBER(ISNA()) patterns. Pair error handling with conditional formatting to color missing entries red.

Does this work in older Excel versions?

XMATCH is available in Microsoft 365, Excel 2021, and Excel Online. Earlier versions such as 2019 or 2016 do not include it. For compatibility, fall back to MATCH or write a small VBA wrapper that mimics XMATCH behavior.

What about performance with large datasets?

Internal benchmarks show XMATCH outperforming MATCH by about 20-30 percent on lists above 100,000 rows because of the optimized calculation engine. To maximize speed, minimize volatile functions in the workbook, restrict lookup_array to the used range (not entire columns), and avoid on-the-fly type conversions.

Conclusion

Mastering XMATCH unlocks faster, clearer, and more robust position lookups in modern Excel. Whether you are tracking inventory, analyzing project timelines, or building interactive dashboards, knowing how to pinpoint an item’s exact row or column underpins many advanced formulas. By practicing the techniques in this tutorial—basic lookups, last-occurrence searches, and dynamic spill integrations—you are better prepared to leverage other modern Excel functions that depend on accurate indices. Keep experimenting with real business data, document your match_mode choices, and you will soon incorporate XMATCH into your everyday analytical toolkit with confidence.

We use tracking cookies to understand how you use the product and help us improve it. Please accept cookies to help us improve.