Function Problems

Use TRIM and CLEAN with Excel XLOOKUP for Invoice Numbers

Amos GikundaAmos Gikunda Dec 2, 2026 868 views

Question details

The user wants to remove unwanted characters from invoice numbers before matching them and retrieving amounts from an external workbook.

Use TRIM and CLEAN with Excel XLOOKUP for Invoice Numbers
Product
Microsoft Excel
Device & OS
not provided
Scenario
Use XLOOKUP to match invoice numbers in one workbook against data in another workbook.
Observed behavior
Extra spaces or nonprinting characters can prevent otherwise matching invoice numbers from returning the expected amount.
Before you start

Open both workbooks and identify the invoice number and amount columns in the source workbook. Check whether invoice numbers must retain leading zeros and whether amounts are stored as numbers or text.

Solution 1Recommended

Clean both sides of the Excel XLOOKUP match

Use this approach when spaces or nonprinting characters in invoice numbers prevent an exact match.

TRIM removes leading and trailing ordinary spaces and reduces repeated ordinary spaces within text. CLEAN removes common nonprinting characters, while SUBSTITUTE replaces nonbreaking spaces with ordinary spaces.

The example assumes the invoice number to find is in A2, the source invoice numbers are in column A, and the amounts to return are in column B. Adjust the workbook name, sheet name, and ranges to match your files.

1
Open the source workbook

In Excel, open the workbook containing the lookup and the external Invoices.xlsx workbook containing the invoice data.

2
Enter the lookup formula

Select the cell where you want the amount and enter: =XLOOKUP(TRIM(CLEAN(SUBSTITUTE(A2&"",CHAR(160)," "))),TRIM(CLEAN(SUBSTITUTE('[Invoices.xlsx]Sheet1'!$A$2:$A$1000&"",CHAR(160)," "))),'[Invoices.xlsx]Sheet1'!$B$2:$B$1000,"Not found")

3
Check the results

Press Enter and copy the formula down for other invoice numbers. If a match is still missing, inspect the source and lookup cells in the formula bar for other characters or differences in leading zeros.

4
Check additional matching criteria

If the match also depends on an amount, compare the amount columns as numbers on both sides. If you concatenate fields into a lookup key, clean and format each field consistently and use the same separator on both sides.

Clean both sides of the Excel XLOOKUP match
Preserve invoice number formatting: Adding &"" converts values to text for comparison, but it cannot restore leading zeros already lost from a numeric cell. Store invoice numbers as text when those zeros are significant.
Work with invoice data in WPS

Match cleaned invoice numbers in WPS Spreadsheets

In WPS Spreadsheets, create a cleaned helper column and use INDEX and MATCH to retrieve invoice amounts without relying on XLOOKUP.

  1. 1. Open the invoice data: Open the workbooks in WPS Spreadsheets. Copy the source invoice numbers into column A and their corresponding amounts into column B of a worksheet.
  2. 2. Create a cleaned helper column: In C2, enter =TRIM(CLEAN(SUBSTITUTE(A2&"",CHAR(160)," "))) and fill the formula down alongside the source data.
  3. 3. Enter the invoice to find: Enter or paste the invoice number to look up in D2, preserving any significant leading zeros as text.
  4. 4. Retrieve the amount: In E2, enter =IFERROR(INDEX($B$2:$B$1000,MATCH(TRIM(CLEAN(SUBSTITUTE(D2&"",CHAR(160)," "))),$C$2:$C$1000,0)),"Not found"). Adjust the ranges to include your source rows.
Clean spaces and common nonprinting characters from invoice numbersRetrieve matching amounts with INDEX and MATCHOpen and edit Microsoft Excel XLSX workbooksUse a familiar spreadsheet interface
QA img-9

Frequently Asked Questions

Why does TRIM alone not fix every invoice match?

TRIM handles ordinary spaces, but it does not remove nonbreaking spaces or all nonprinting characters. Use SUBSTITUTE with CHAR(160) for nonbreaking spaces and CLEAN for common nonprinting characters.

What if an invoice number still returns Not found?

Check both cells in the formula bar for different characters, missing leading zeros, or spelling differences. The formula converts values to text, but it cannot recover zeros that were removed when a number was entered.

Can I match both an invoice number and an amount?

Yes. Use both fields as matching criteria, or create a helper key on each side using the same cleaned invoice number, consistently formatted amount, and separator. Make sure amounts are stored as the same data type.

What can I use if my spreadsheet does not support XLOOKUP?

Create a cleaned helper column with TRIM, CLEAN, and SUBSTITUTE, then use INDEX and MATCH against that column to return the amount.