How to Get First Match Cell Contains in Excel
Learn multiple Excel methods to get first match cell contains with step-by-step examples and practical applications.
How to Get First Match Cell Contains in Excel
Why This Task Matters in Excel
Modern worksheets are rarely pristine lists with one-word labels. Sales pipelines contain notes such as “Opportunity – follow up”, inventory files carry product codes plus descriptions like “BK-453-Red-Large”, and social-media exports bundle hashtags, mentions, and narrative in the same cell. When analysts need to find the first record that contains a certain word or partial code—not an exact value—the usual VLOOKUP or simple MATCH fails. Quickly locating “Red” in a crowded SKU list, identifying the first “overdue” task in a project tracker, or pulling the earliest comment that mentions “refund” in a customer log are all examples of this pattern.
Across industries, the need appears constantly:
- Retail: Find the first product whose description contains “XL” to confirm stock availability
- Finance: Identify the earliest transaction line that contains “fee” to start fee-reconciliation
- Marketing: Retrieve the first tweet text that contains “launch” for campaign reporting
- Manufacturing: Pinpoint the first work-order row whose notes field includes “rework”
Excel excels (pun intended) at quick, flexible data exploration. The grid layout, dynamic arrays, and wildcard-aware lookup functions mean analysts can build a reliable “first match” locator in seconds—long before a database administrator could even spin up a SQL view. Failing to master this seemingly modest trick has heavy consequences: manual scrolling, missed deadlines because of overlooked rows, and error-prone copy-paste quick fixes. Moreover, proficiency here links directly to other lookup skills such as fuzzy matching, data cleansing, and automated reporting. Once you understand how to get the first contains-type match, you can extend the same logic to pull all matches, flag duplicates, drive conditional formatting, or feed dashboards.
Best Excel Approach
The fastest, most transparent modern solution is the wildcard-enabled XLOOKUP. When you set the match mode to exact and allow wildcards, XLOOKUP searches from top to bottom and returns the first item whose text string includes the requested substring.
=XLOOKUP("*"&F1&"*", [A2:A100], [A2:A100], "Not found", 0, 1)
Explanation of arguments
- F1 – cell that holds the substring you want to locate
- [A2:A100] – lookup array containing the text you will search through
- [A2:A100] – return array (often the same as lookup array when you just need the found text)
- \"Not found\" – value returned if no cell contains your substring
- 0 – exact match mode (required for wildcards)
- 1 – search mode; 1 means search top-to-bottom (default)
Why this is the best default:
- Native wildcard awareness (“*” and “?”)
- No need for Ctrl + Shift + Enter; spills automatically if you later expand to multiple results
- Optional sixth argument lets you reverse search when you need the last match
- Clear, readable syntax for less-experienced colleagues
If you are on Excel 2016 or earlier and do not have XLOOKUP, the classic alternative is an INDEX-MATCH array formula that converts the contains test into a TRUE/FALSE sequence.
=INDEX([A2:A100], MATCH(TRUE, ISNUMBER(SEARCH(F1, [A2:A100])), 0))
Commit with Ctrl + Shift + Enter in legacy versions. The SEARCH function returns a number the moment it finds the substring; ISNUMBER converts that to TRUE. MATCH then finds the position of the first TRUE, and INDEX retrieves the corresponding cell.
Parameters and Inputs
- Lookup value – usually a single word or fragment (text). Keep it in a dedicated input cell such as [F1] so users do not edit formulas directly.
- Lookup array – the column or row you want to search through. Text, numbers, or mixed content allowed, but numbers are interpreted literally, not as text fragments.
- Return array – optional if you only need the found text; separate if you want a code from column B while searching the description in column C.
- Wildcards – an asterisk represents any sequence of characters; a question mark represents a single character. Always concatenate them inside formulas.
- Search mode – in XLOOKUP, 1 means top-down, −1 means bottom-up. Choose 1 for “first” match.
- Data preparation – trim leading/trailing spaces with TRIM, fix inconsistent capitalization when using case-sensitive FIND, and remove unprintable characters with CLEAN.
- Edge cases – empty lookup value returns the first blank cell; filter or validate input to block that. Non-text errors in the lookup array (like #DIV/0!) cause the entire array formula to error; wrap it in IFERROR if necessary.
Step-by-Step Examples
Example 1: Basic Scenario
Imagine a simple product list in [A2:A10]:
| A |
|---|
| BK-453-Red-Large |
| BK-454-Blue-Small |
| BK-455-Red-Medium |
| BK-456-Green-Large |
| BK-457-Red-Small |
| BK-458-Blue-Large |
| BK-459-Green-Small |
| BK-460-Red-XL |
| BK-461-Blue-Medium |
Goal: find the first product that contains the text “Red”.
- In F1 type : Red
- In G1 enter:
=XLOOKUP("*"&F1&"*", [A2:A10], [A2:A10], "No match", 0, 1)
- Result: BK-453-Red-Large
Why it works: “Red” is interpreted as “anything, followed by Red, followed by anything”. XLOOKUP scans from row 2 downward, hits “BK-453-Red-Large” first, and returns it.
Troubleshooting:
- If you accidentally leave F1 blank, the wildcard expands to “**” which matches every text cell. XLOOKUP then returns the first row automatically. Add data validation to prevent blank input.
- If users type spaces (” Red “) the extra spacing prevents SEARCH from finding it. Wrap the lookup value inside TRIM or educate users.
Variations:
- Split the return array:
XLOOKUP("*"&F1&"*", [A2:A10], [B2:B10])to get the matching product price from column B. - Make the search case-sensitive by using FIND inside INDEX-MATCH, shown later in the advanced example.
Example 2: Real-World Application
Scenario: A customer support sheet logs all ticket notes in column C. Column A holds ticket numbers, column B dates, column C the free-text notes. Management wants to retrieve the first ticket where the note mentions “refund” (not necessarily the first chronological date, but first in the sheet order—usually sorted oldest to newest).
Sample structure:
| A (Ticket) | B (Date) | C (Notes) |
|---|---|---|
| 3451 | 2023-01-07 | “Customer requested status update” |
| 3452 | 2023-01-08 | “Refund requested due to delay” |
| 3453 | 2023-01-09 | “Follow-up email sent” |
| 3454 | 2023-01-09 | “Partial refund processed” |
| … | … | … |
Steps:
- Place the keyword “refund” (lowercase fine) in F1.
- Ticket number result cell G1:
=XLOOKUP("*"&F1&"*", [C:C], [A:A], "No ticket found", 0, 1)
- Date result cell H1:
=XLOOKUP("*"&F1&"*", [C:C], [B:B], "N/A", 0, 1)
Output: Ticket 3452 and date 2023-01-08.
Business impact: Support managers instantly identify the earliest refund conversation without scanning hundreds of notes. They can escalate or analyze recurring issues. This also scales: switch the lookup value to “escalation” or “callback” to audit other event types.
Integration with other features:
- Conditional Formatting – highlight the matching row: create a rule with
=ISNUMBER(SEARCH($F$1,$C2)). - Dashboards – the XLOOKUP cell can feed Power Query or Power Pivot measures as a slicer default.
- Data expansion – because the formulas reference entire columns, new tickets append automatically. Performance remains acceptable because SEARCH operates on text only, not arrays of numbers.
Performance notes: On sheets with 100 000+ notes, wildcard XLOOKUP stays responsive. However, very long notes (over 32 768 characters) exceed cell limits; store large text in an external system and pull only a snippet.
Example 3: Advanced Technique
Requirement: Return the first match case-sensitive and across a filtered subset (for example, only open tasks). Dynamic arrays make this elegant.
Dataset in [A2:D50]:
- Column A – Task ID
- Column B – Status: “Open”, “Closed”, “Hold”
- Column C – Assigned To
- Column D – Description text
Goal: Among tasks still “Open”, fetch the first description that contains the exact, case-sensitive fragment in F1.
Step 1: Build a dynamic filtered list of only open tasks.
=FILTER([D2:D50], [B2:B50]="Open")
Step 2: Use INDEX-MATCH with FIND (case-sensitive) to locate the fragment inside that spill range. You cannot directly run MATCH over a spill, so wrap it in TAKE or let it remain:
=LET(
openDesc, FILTER([D2:D50], [B2:B50]="Open"),
pos, MATCH(TRUE, ISNUMBER(FIND(F1, openDesc)), 0),
TAKE(openDesc, 1, 1 + pos - 1)
)
Explanation:
- LET creates a named variable openDesc that is an array of descriptions for open tasks.
- FIND returns a number only when it sees the exact capitalization.
- MATCH locates the first TRUE.
- TAKE extracts the position from openDesc (an INDEX alternative compatible with dynamic arrays).
Edge cases handled: If no open task contains the fragment, the MATCH call errors. Wrap the entire block in IFERROR to return “None”.
Performance tips: By filtering first, you never run FIND across closed tasks, which may be 90 percent of data in a mature project.
Professional insights:
- LET keeps formulas readable and faster because Excel calculates openDesc once.
- This pattern is easily upgraded to LAMBDAs for reusable custom functions like FirstMatchContains(openRange, searchText).
- Worksheets shared with colleagues on older versions can still consume the result because dynamic arrays spill values; they simply see the result in the top-left cell, although they cannot edit the formula.
Tips and Best Practices
- Always store the search fragment in a separate input cell; this avoids accidental formula edits and enables drop-down lists.
- Wrap lookup arrays in TRIM to remove errant spaces from imported systems:
TRIM([A2:A100]). - Cache heavy calculations with LET to boost performance, especially when SEARCH or FIND runs on 100 k-row logs.
- Combine SEARCH with UPPER to achieve case-insensitive matching without worrying about mixed text:
SEARCH(UPPER(F1), UPPER([A2:A100])). - For multilingual data, normalize diacritics using SUBSTITUTE before searching (replace \"á\" with \"a\").
- Document wildcard behavior clearly in tooltip cells so casual users know to avoid reserved characters like ? and * in ordinary typing.
Common Mistakes to Avoid
- Forgetting to concatenate wildcards in XLOOKUP. Writing
"*"&F1&"*"is mandatory; otherwise XLOOKUP searches for the literal asterisks.
- Symptom: formula returns “Not found” even though the text is present.
- Fix: edit the formula, add wildcards.
- Using VLOOKUP in exact match mode expecting contains behavior. VLOOKUP always needs the full value unless the first column is sorted and you allow approximate mode, which still does not handle contains.
- Fix: switch to XLOOKUP or INDEX-MATCH as shown.
- Neglecting array entry (Ctrl + Shift + Enter) in legacy INDEX-MATCH formulas, causing MATCH(TRUE,…) to error.
- Symptom: #N/A or #VALUE!.
- Fix: commit as array formula or upgrade to dynamic arrays.
- Ignoring case when it matters. SEARCH is case-insensitive. If “Open” versus “open” is significant, use FIND or EXACT inside the logic.
- Consequence: unintended matches.
- Fix: choose FIND or compare UPPER converted text.
- Leaving lookup value blank. An empty string with wildcards matches the first text row, producing misleading results.
- Prevention: add data validation rule “text length ≥ 1” or wrap formula in IF(F\1=\"\",\"\",formula).
Alternative Methods
| Method | Excel Version | Pros | Cons | Best For |
|---|---|---|---|---|
| XLOOKUP with wildcards | 365, 2021 | Simple, spill-aware, bidirectional search | Not available pre-2019 | Most modern workbooks |
| INDEX-MATCH-SEARCH | 2010+ | Works everywhere, customizable | Array entry needed in old Excel, verbose | Corporate environments on mixed versions |
| FILTER + TAKE | 365 | Dynamic arrays, can return multiple matches | Requires 365, not case-sensitive alone | Dashboards needing all matches |
| VBA loop | Any | Unlimited customization, case-sensitive, can ignore hidden rows | Requires macros, security prompts, slower | Highly customized workflows |
| Power Query | 2016+ | Handles millions of rows, GUI transformations | Refresh cycle, formula not live | ETL pipelines and data warehouses |
Use XLOOKUP when you are sure the file will live in Office 365 or 2021. Stick with INDEX-MATCH for compatibility. Leverage Power Query if the dataset routinely exceeds worksheet row limits or needs heavy pre-cleansing.
FAQ
When should I use this approach?
Use it any time you need to find the first entry containing a fragment rather than an exact value: part numbers, keywords in comments, or partial IDs. It is ideal for top-to-bottom analysis where the sheet order carries meaning, such as chronological logs.
Can this work across multiple sheets?
Yes. Point the lookup array to another sheet, e.g., XLOOKUP("*"&F1&"*", Sheet2![A:A], Sheet2![A:A]). For INDEX-MATCH precede the range with the sheet name. If the sheets are in separate workbooks, keep both files open or reference them with full workbook paths.
What are the limitations?
Wildcard searches treat the question mark and asterisk as special characters, so searching for a literal * requires escaping (~*). SEARCH fails on arrays containing errors. XLOOKUP cannot do case-sensitive wildcard searches directly; pair with FILTER and FIND for that.
How do I handle errors?
Wrap the entire formula in IFERROR: IFERROR(XLOOKUP(...), "No match"). For debugging, temporarily remove IFERROR to reveal whether the error is #N/A (no match) or #VALUE! (mismatched dimensions).
Does this work in older Excel versions?
INDEX-MATCH-SEARCH works back to Excel 2003. Remember to enter with Ctrl + Shift + Enter. XLOOKUP and FILTER require Microsoft 365 or Excel 2021. Dynamic LET also needs 365.
What about performance with large datasets?
Wildcard XLOOKUP on 100 k rows is fast in 365 due to optimized C-code underneath. For multi-million row CSVs, import through Power Query, filter down, then apply the formula on the smaller result set. Avoid volatile functions like INDIRECT inside the lookup setup.
Conclusion
Mastering “first match contains” lookups eliminates guesswork and scrolling, enabling immediate insight from messy, real-world text data. Whether you embrace the elegant XLOOKUP wildcard or fallback to robust INDEX-MATCH, the principle stays the same: convert “does this cell contain my fragment?” into a TRUE/FALSE array, locate the first TRUE, and return the associated value. This skill sits at the crossroads of lookup logic, array formulas, and data cleanup—core competencies for any Excel professional. Keep practicing on your own datasets, experiment with case sensitivity, and integrate the technique into dashboards and automated reports. With this tool in your arsenal, you will spend less time hunting for rows and more time acting on information.
Related Articles
How to Show the 10 Most Common Text Values in Excel
Learn multiple Excel methods to list the 10 most frequent text values—complete with step-by-step examples, business use cases, and expert tips.
How to Abbreviate Names Or Words in Excel
Learn multiple Excel methods to abbreviate names or words with step-by-step examples and practical applications.
How to Abbreviate State Names in Excel
Learn multiple Excel methods to abbreviate state names with step-by-step examples, professional tips, and real-world applications.