Fix Excel MATCH Searches for Trailing Spaces and Partial Text
Question details
Find values in Excel when source cells contain trailing spaces or the search text is part of a longer cell.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A user searches a list of text values with MATCH and also needs to identify cells containing a text feature.
- Observed behavior
- An exact MATCH can miss values with trailing spaces and does not find a search term embedded in longer text.
Identify the search cell and the range to search. The examples below use D2 for the search term and C2:C1001 for source text; adjust these references to match your worksheet.
Clean spaces before using an exact MATCH
Use a helper column when trailing spaces prevent otherwise identical text from matching.
In an empty helper cell such as E2, enter =TRIM(C2), then fill the formula down through E1001.
In an empty result cell, enter =IFERROR(MATCH(TRIM($D$2),$E$2:$E$1001,0),""). MATCH returns the position within the helper range, or a blank if no match is found.
To return the corresponding source value instead of its position, enter =IFERROR(INDEX($C$2:$C$1001,MATCH(TRIM($D$2),$E$2:$E$1001,0)),"") in an empty cell.

Find partial text with a wildcard MATCH
Use wildcards when the search term can appear anywhere within a longer cell.
Return all cells containing a search term with FILTER
Use FILTER when you need a list of matching cells rather than only the first position or a count.
Find Cleaned and Partial Text in WPS Spreadsheet
Use TRIM and MATCH in WPS Spreadsheet to search cleaned text, or add wildcards to find a term within longer cells.
- 1. Open the workbook: Open WPS Spreadsheet and select Open to choose your Excel workbook.
- 2. Clean the source values: In an empty helper column, enter =TRIM(C2) in E2 and fill it down alongside the source data.
- 3. Run an exact search: Enter =IFERROR(MATCH(TRIM($D$2),$E$2:$E$1001,0),"") in an empty cell, adjusting the ranges to your data.
- 4. Search for partial text: For a partial match, enter =IFERROR(MATCH("*"&TRIM($D$2)&"*",$C$2:$C$1001,0),"") in an empty cell.

Frequently Asked Questions
Why does MATCH miss a value that looks identical?
The source or search cell may contain extra spaces. Use TRIM in a helper column and apply TRIM to the search cell before running MATCH.
How can I find a word inside a longer Excel cell?
Use =MATCH("*"&D2&"*",C2:C1001,0) to find the first cell containing the text in D2. MATCH returns its position within the range.
Why does TRIM not remove every space?
TRIM does not remove nonbreaking spaces. In a helper cell, use =TRIM(SUBSTITUTE(C2,CHAR(160)," ")) to replace them before trimming.
Can I return every matching cell instead of the first one?
In Excel versions that support FILTER, use =FILTER(C2:C1001,ISNUMBER(SEARCH(D2,C2:C1001)),"No matches") to list cells containing the term in D2.




