Excel · ChatGPT

How to Remove Spaces in Excel with ChatGPT

Clean leading, trailing, extra, and hidden spaces without overwriting your original data. Use a tested prompt to identify the type of whitespace, apply the right Excel formula, and verify the cleaned values before using them in lookups or reports.

Choose your situation — copy the tested prompt:
I have a column of customer names in Excel with inconsistent spaces.

Here are sample values from column A. In the “Visible representation” below, each · represents one actual normal space character:

| Cell | Visible representation |
| A2 | ··Acme·Corp |
| A3 | Beta·Ltd·· |
| A4 | Gamma··Industries |
| A5 | ··Delta···Services·· |

The actual Excel cells contain normal spaces, not the · character.

I need to clean these values so that:
- leading spaces are removed
- trailing spaces are removed
- multiple spaces between words are reduced to a single space
- the actual words and punctuation are not changed

Please:
1. Give me the Excel formula I should use in B2.
2. Show the expected cleaned result for each sample row.
3. For the results table, use · again to make every remaining space visible.
4. Explain exactly what the formula removes and what it preserves.
5. Tell me whether the formula would also remove non-breaking spaces or other invisible characters imported from a website or external system.
6. If it would not, say so clearly rather than assuming all spaces are the same.

Do not modify the original values in column A.

Use this when the unwanted characters are ordinary spaces. The · marks in the example only make the spaces visible; they are not characters stored in Excel.

I have customer names in Excel that look clean, but some comparisons are still failing.

The values were copied from a website.

In column A I have:

| Cell | Visible value |
| A2 | Acme Corp |
| A3 | Beta Ltd |
| A4 | Gamma Industries |

The cells look normal on screen.

However, these tests return unexpected results:

=A2="Acme Corp"
returns FALSE.

And:

=TRIM(A2)="Acme Corp"
also returns FALSE.

Additional information:
- The character after Corp in A2 is a non-breaking space, CHAR(160).
- The same type of hidden character may appear at the beginning or end of the other values.
- I do not want to overwrite column A.

Please:
1. Explain why TRIM(A2) does not fix the problem.
2. Give me a formula to use in B2 that removes the non-breaking spaces while preserving the actual customer name.
3. Show the expected cleaned result for A2:A4.
4. Explain what each part of the formula does.
5. Tell me whether this solution also guarantees removal of every possible invisible or Unicode whitespace character.
6. If it does not, say so clearly and explain the limitation.

Do not assume that all whitespace characters in Excel are normal spaces.

Use this when TRIM still leaves a value unequal to text that looks identical — especially after a web or system import.

I have an Excel lookup that is returning #N/A even though the customer IDs appear to match.

Here is the imported customer data:

| Cell | Customer ID | Customer |
| A2 | C-1042[trailing space] | Acme Corp |
| A3 | [leading space]C-1057 | Beta Ltd |
| A4 | C-1081 | Gamma Inc |

And here is the reference table on sheet Regions:

| Customer ID | Region |
| C-1042 | West |
| C-1057 | East |
| C-1081 | South |

The lookup formula is:

=XLOOKUP(A2,Regions!A:A,Regions!B:B)

For some rows it returns #N/A.

Additional information:
- The IDs in the imported table may contain leading or trailing normal spaces.
- The visible characters in the IDs are otherwise correct.
- I do not want to modify the original imported values in column A.
- Do not assume the XLOOKUP formula itself is the problem.

Please:
1. Explain why the lookup can fail even when the IDs look identical.
2. Show me how to verify that hidden spaces are present.
3. Give me a formula in a helper column to clean the imported IDs without changing valid characters inside the ID.
4. Show the expected cleaned result for all three IDs.
5. Give me the corrected XLOOKUP approach using the cleaned values.
6. Explain whether TRIM is safe here and what it would do if an ID legitimately contained spaces inside it.
7. Mention any limitation if the imported data contains non-breaking spaces rather than normal spaces.

Do not overwrite the original imported IDs.

Use this when lookup keys appear identical but exact-match XLOOKUP or VLOOKUP still fails.

Before — ordinary spaces are inconsistent
RowStored text — spaces shown as ·Problem
2··Acme·CorpLeading spaces
3Beta·Ltd··Trailing spaces
4Gamma··IndustriesDouble internal space
5··Delta···Services··All three
· is only a visual marker here. The Excel cells contain normal space characters.
After — TRIM cleans normal spaces
Formula in B2Cleaned resultStatus
Acme·CorpClean ✓
Beta·LtdClean ✓
Gamma·IndustriesClean ✓
Delta·ServicesClean ✓
Verified ChatGPT result
=TRIM(A2)

Removes normal leading/trailing spaces and reduces repeated normal spaces between words to one. It does not guarantee removal of CHAR(160) or every invisible Unicode character.
Before — text looks clean, but equality still fails
CellVisible valueTestResult
A2Acme Corp[NBSP]=A2="Acme Corp"FALSE
A2Acme Corp[NBSP]=TRIM(A2)="Acme Corp"FALSE
TRIM targets normal space CHAR(32); the imported character here is CHAR(160).
After — convert CHAR(160), then trim
Helper formulaCleaned valueVerification
Acme Corp=B2="Acme Corp" → TRUE ✓
Beta LtdClean ✓
Gamma IndustriesClean ✓
Verified ChatGPT diagnosis
SUBSTITUTE changes CHAR(160) to a normal space.
TRIM then removes leading/trailing normal spaces and collapses repeats.
This is targeted cleanup — not a universal Unicode-whitespace remover.
Before — hidden spaces break exact-match XLOOKUP
Imported IDReference IDXLOOKUP result
C-1042·C-1042#N/A
·C-1057C-1057#N/A
C-1081C-1081South ✓
Check: =LEN(A2) vs =LEN(TRIM(A2))   |   =A2=TRIM(A2)
After — clean a helper key, then look it up
Original IDHelper CRegion
C-1042·C-1042West ✓
·C-1057C-1057East ✓
C-1081C-1081South ✓
Verified formulas
Helper C2:
=TRIM(A2)

Lookup using cleaned key:
=XLOOKUP(C2,Regions!A:A,Regions!B:B)

If the import contains CHAR(160), clean that character explicitly before the lookup.
Why spaces in Excel are hard to remove — 4 common cases
Leading / trailing spaces
Text has normal CHAR(32) around the value → use TRIM
Common
Extra spaces between words
Gamma··Industries → TRIM reduces repeated normal spaces to one
Common
TRIM still fails
Web/import data may contain CHAR(160) → convert it with SUBSTITUTE first
Easy to miss
Lookup returns #N/A
Keys look identical but one contains hidden spaces → clean a helper key before XLOOKUP
Check keys

How to Remove Spaces in Excel Safely

Clean spaces without overwriting your source data — 5 steps
1

Keep the imported column unchanged

Add a helper column instead of editing the source values in place. This lets you compare the original and cleaned text, verify the result, and recover easily if the imported data contains meaningful internal spaces.

2

Choose the prompt that matches the symptom

Use the first prompt for ordinary leading, trailing, or repeated spaces. Use the second when TRIM still fails after a web/system import. Use the third when hidden spaces are breaking an exact-match lookup.

3

Test the cleanup formula in the helper column

For normal spaces, start with =TRIM(A2). For a confirmed non-breaking space CHAR(160), use =TRIM(SUBSTITUTE(A2,CHAR(160)," ")). Target the character you actually have instead of assuming every invisible character is the same.

4

Verify that the text really changed as expected

Compare LEN(A2) with LEN(TRIM(A2)) for normal-space issues, or test cleaned text directly with a formula such as =B2="Acme Corp". A visual match alone is not proof that two strings are identical.

5

Use the cleaned helper values downstream

Point XLOOKUP, comparisons, or other formulas at the verified helper column. Only replace the original values if you are certain the cleanup preserved every meaningful character your IDs, names, or codes require.

Important: TRIM is not a universal invisible-character remover. It is safe for the normal-space cases shown here, but imported web data can contain non-breaking spaces, zero-width characters, or other Unicode whitespace that requires targeted diagnosis.

Frequently asked questions

How do I remove leading and trailing spaces in Excel?
Use =TRIM(A2) in a helper column. TRIM removes normal leading and trailing spaces and reduces repeated normal spaces between words to a single space. It preserves a single normal space between words.
Why is TRIM not removing spaces in Excel?
TRIM is designed for normal ASCII spaces, CHAR(32). Data copied from websites or external systems can contain non-breaking spaces such as CHAR(160), which can look identical on screen but remain after TRIM.
How do I remove non-breaking spaces in Excel?
For a confirmed CHAR(160), use =TRIM(SUBSTITUTE(A2,CHAR(160)," ")). SUBSTITUTE converts the non-breaking space to a normal space; TRIM then removes leading/trailing spaces and collapses repeated normal spaces.
Can hidden spaces cause XLOOKUP or VLOOKUP to return #N/A?
Yes. Exact-match lookups treat C-1042 and C-1042 as different text values. Clean the imported key in a helper column, verify it, and use that cleaned key in the lookup instead of assuming the lookup formula itself is wrong.
Does TRIM remove every invisible character in Excel?
No. TRIM handles normal spaces but does not guarantee removal of every non-breaking, Unicode, zero-width, or other invisible character. The safest approach is to identify the character actually present and use targeted cleanup rather than stacking functions blindly.

Related Excel workflows