Cleaning data so lookups match

1 / 4

These account numbers came from an export and are stored as text: see how they sit on the left. The table has real numbers.

keyboard Typing formulas is easiest on a computer with a keyboard.

A1
ABCDEF
1Account no.NameAccount no.Name
21997Elif Brennan2109
31647Uma Garcia1976
41381Priya Tanaka1304
52298Chloe Garcia1731
62858Lena Ibrahim1997
71549Mateo Novak
81731Victor Costa
92109Oscar Murphy
101976Amara Patel
111304Nadia Novak
12
13
14
15
numbers
text
Type to enter a value or a formula starting with =. F2 edits, F4 adds $ to a reference.
Study notes

How TRIM and VALUE works

  • Why does a lookup say #N/A when the value is right there?

    Because the two values only look the same. The usual culprits:

    • Extra spaces: "C1042 " with a space at the end is not "C1042".
    • Numbers stored as text: "1042" from an export is not the number 1042.
    • Different punctuation: "AB-12" is not "AB12".
  • How do you fix it inside the lookup?

    Clean the value you look up with, so the original data stays untouched:

    • =XLOOKUP(TRIM(D2),A2:A11,B2:B11) removes spaces at the start and end.
    • =XLOOKUP(VALUE(D2),A2:A11,B2:B11) turns "1042" into 1042.
    • =XLOOKUP(SUBSTITUTE(D2,"-",""),A2:A11,B2:B11) removes the dashes.

    They can be combined: VALUE(TRIM(D2)).

  • What if the table is the messy side?

    Clean the lookup range instead: =XLOOKUP(D2,TRIM($A$2:$A$11),$B$2:$B$11) works in Excel 365, which cleans every cell as it searches. In older Excel, add a cleaned helper column to the table.

  • How do you spot the problem?

    Compare the two cells with =D2=A5 (FALSE means they differ), check the lengths with LEN, and look for text sitting on the left of the cell. The Lookup & Merge tool on this site explains every miss for you.

Know someone fighting with a spreadsheet? Send them this page.