Function Problems

Fix Excel MATCH Searches for Trailing Spaces and Partial Text

Huda QurayshiHuda Qurayshi Dec 2, 2026 868 views

Question details

Find values in Excel when source cells contain trailing spaces or the search text is part of a longer cell.

Fix Excel MATCH Searches for Trailing Spaces and Partial Text
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.
Before you start

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.

Solution 1Recommended

Clean spaces before using an exact MATCH

Use a helper column when trailing spaces prevent otherwise identical text from matching.

1
Clean the source text

In an empty helper cell such as E2, enter =TRIM(C2), then fill the formula down through E1001.

2
Match the cleaned values

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.

3
Return the original value

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.

Clean spaces before using an exact MATCH
Check for nonbreaking spaces: TRIM removes ordinary spaces but not nonbreaking spaces. If imported text still does not match, use =TRIM(SUBSTITUTE(C2,CHAR(160)," ")) in the helper column.
WPS Spreadsheet

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. 1. Open the workbook: Open WPS Spreadsheet and select Open to choose your Excel workbook.
  2. 2. Clean the source values: In an empty helper column, enter =TRIM(C2) in E2 and fill it down alongside the source data.
  3. 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. 4. Search for partial text: For a partial match, enter =IFERROR(MATCH("*"&TRIM($D$2)&"*",$C$2:$C$1001,0),"") in an empty cell.
Clean trailing spaces with TRIM before an exact MATCH.Find partial text with MATCH wildcards.Open and edit Microsoft Excel XLSX and XLS files.Work in a familiar spreadsheet interface.
QA img-9

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.