How to Remove Extra Spaces in Google Sheets: Leading, Trailing and Double Spaces, Non-Breaking Spaces, Line Breaks and Why TRIM Isn’t Working (2026)

Extra spaces are invisible in a cell but not to a formula: “ana@example.com ” with a trailing space is a different value from “ana@example.com”, so formulas such as COUNTIF and EXACT treat them as different values and duplicates go unnoticed. Google’s TRIM help page puts it plainly: spaces in front of or after text are significant when the text is used in formulas or data validation. This guide finds the stray spaces, removes the normal ones with TRIM, handles the two cases TRIM leaves behind (non-breaking spaces and line breaks), gives one formula that cleans all of it, and shows how cleaning a column changes a duplicate check.

The short answer

The example

A contact list with ten rows. Some names and emails have spaces before, after or between them, row 6 has non-breaking spaces, and row 8 has a line break between first and last name. Three people appear twice (rows 2 and 4, 3 and 7, 6 and 9), and Eli Moss appears twice too (rows 8 and 11).

RowA: NameB: EmailWhat’s wrong
2  Ana Ruizana@example.com two leading spaces in the name, a trailing space after the email
3Ben  Coleben@example.comtwo spaces between the names
4Ana Ruizana@example.comclean
5Cara Diaz cara@example.coma trailing space after the name
6Dev[non-breaking space]Pateldev@example.com[non-breaking space]a non-breaking space in the name and after the email
7Ben Cole ben@example.coma leading space before the email
8Eli[line break]Mosseli@example.coma line break between the names
9Dev Pateldev@example.comclean
10Fay  Lee fay@example.coma double space and a trailing space
11Eli Mosseli@example.comclean

The plan is helper columns next to the data: C to try TRIM, D and E for the fully cleaned name and email, and G and H to count duplicates before and after. You can delete them once the clean text is pasted back.

Step 1: find the hidden spaces

You can’t see a trailing space, but you can measure it. LEN counts all characters, even spaces and non-printing characters, so comparing the length before and after TRIM shows how many spaces TRIM would remove:

=LEN(A2)-LEN(TRIM(A2))

It returns 2 for row 2 (two leading spaces), 1 for rows 3 and 5, 2 for row 10 and 0 for the rest. Rows 6 and 8 also return 0, even though they aren’t clean: what they contain isn’t a normal space. To find out what a character is, CODE returns the numeric Unicode value of the first character of a string, so pair it with MID to pick the 4th character, the one right after “Dev” and “Eli”:

=CODE(MID(A6, 4, 1))

That returns 160, a non-breaking space. =CODE(MID(A8, 4, 1)) returns 10, a line break. A normal space is 32.

Step 2: remove leading, trailing and double spaces with TRIM

Put this in C2 and fill it down to C11:

=TRIM(A2)

Google describes TRIM as removing leading, trailing and repeated spaces, leaving just a single space between words. “  Ana Ruiz”, “Ben  Cole” and “Fay  Lee ” come out as “Ana Ruiz”, “Ben Cole” and “Fay Lee”:

RowC: =TRIM(A2)LEN(A)−LEN(TRIM(A))
2Ana Ruiz2
3Ben Cole1
4Ana Ruiz0
5Cara Diaz1
6Dev[non-breaking space]Patel0
7Ben Cole0
8Eli[line break]Moss0
9Dev Patel0
10Fay Lee2
11Eli Moss0

Rows 6 and 8 come back unchanged. Those are the two problems TRIM doesn’t fix, covered in the next two steps.

Trim whitespace: the same fix without a formula

To clean cells in place, select the range and choose Data › Data cleanup › Trim whitespace. Google’s data cleanup help page says it removes extra leading, trailing or excessive spaces in the selected range. It changes the cells themselves, so duplicate the tab first if you want to keep the original.

Step 3: non-breaking spaces, CHAR(160)

This is the space TRIM leaves behind. Both the TRIM page and the Trim whitespace instructions note that a non-breaking space (the   of web pages) will not be trimmed. It looks like a space but it is character 160, not 32. Turn it into a normal space with SUBSTITUTE and CHAR, then trim:

=TRIM(SUBSTITUTE(A2, CHAR(160), " "))

Row 6 becomes “Dev Patel”. SUBSTITUTE replaces every occurrence by default, so a cell with several non-breaking spaces is fixed in one pass.

Step 4: line breaks and other non-printing characters

A line break inside a cell is character 10. TRIM only deals with spaces, so replace the line break with a space first:

=TRIM(SUBSTITUTE(A2, CHAR(10), " "))

Row 8 becomes “Eli Moss”. You may see CLEAN suggested for this. It returns the text with non-printable ASCII characters removed, and a line break is one of them, but it deletes the character without putting anything in its place: =CLEAN(A8) gives “EliMoss”. Google also notes that CLEAN only removes non-printable ASCII characters, so it doesn’t touch a non-breaking space (character 160 is outside ASCII). Use SUBSTITUTE when the character sits between two words.

Step 5: one formula for all of it

To clean spaces, non-breaking spaces, tabs and line breaks in one go, put this in D2 and fill down to D11 (and the same with B2 in E2 for the emails):

=TRIM(REGEXREPLACE(SUBSTITUTE(A2, CHAR(160), " "), "\s+", " "))

Read it from the inside out. SUBSTITUTE turns non-breaking spaces into normal spaces. REGEXREPLACE then replaces every match of the regular expression \s+ with one space; Google Sheets uses RE2 syntax, where \s means a space, tab, line feed, form feed or carriage return, and + means one or more of them in a row. TRIM finally removes the space left at either end. Every name in column D and every email in column E comes out clean:

RowD: clean nameE: clean emailG: =COUNTIF($B$2:$B$11, B2)H: =COUNTIF($E$2:$E$11, E2)
2Ana Ruizana@example.com12
3Ben Coleben@example.com12
4Ana Ruizana@example.com12
5Cara Diazcara@example.com11
6Dev Pateldev@example.com12
7Ben Coleben@example.com12
8Eli Mosseli@example.com22
9Dev Pateldev@example.com12
10Fay Leefay@example.com11
11Eli Mosseli@example.com22

REGEXREPLACE only works with text, so use this on text columns such as names, emails and notes, not on a column of numbers. To cover the whole column with a single formula in the first cell of an empty column, use ARRAYFORMULA; blank rows stay blank:

=ARRAYFORMULA(IF(A2:A="", "", TRIM(REGEXREPLACE(SUBSTITUTE(A2:A, CHAR(160), " "), "\s+", " "))))

To check which rows the formula actually changed, =EXACT(A2, D2) returns FALSE where the cleaned name differs from the original. EXACT requires identical spaces and hidden characters, so here it is TRUE only for rows 4, 7, 9 and 11.

Step 6: replace the original text

The helper columns are formulas that read from A and B, so deleting the originals would break them. To make the change permanent:

  1. Right-click the sheet tab and choose Duplicate, so you have a copy to go back to.
  2. Select D2:D11 and copy it.
  3. Click A2 and choose Edit › Paste special › Values only.
  4. Do the same for E2:E11 into B2, then delete the helper columns.

Line breaks without a formula: Find and replace

To replace line breaks in place, choose Edit › Find and replace, type \n next to “Find” and a single space next to “Replace with”, tick Search using regular expressions (see Google’s find and replace help page) and click Replace all. Then run Data › Data cleanup › Trim whitespace on the range to tidy up any doubled spaces.

Extra spaces and duplicates

The example has four people entered twice, but on the raw emails in column B a duplicate count finds only one of them:

So clean the spaces before you look for repeats. With clean emails in column E, this flags them:

=IF(COUNTIF($E$2:$E$11, E2)>1, "Duplicate email", "")

To delete the extra rows, first paste the values back as in Step 6, then select the table and choose Data › Data cleanup › Remove duplicates, tick “Data has header row” and only the Email column. It removes 4 rows (rows 4, 7, 9 and 11) and keeps the first row of each pair. If the two copies hold different details, merge the rows instead, and see duplicates that don’t match exactly for case, Gmail dots and typos.

Common problems

FAQ

How do I remove extra spaces in Google Sheets?

Use =TRIM(A2) in a helper column. TRIM removes leading, trailing and repeated spaces and leaves one space between words. Then copy the results and use Edit › Paste special › Values only over the original. To clean a range in place without formulas, select it and choose Data › Data cleanup › Trim whitespace.

Why is TRIM not working in Google Sheets?

If spaces are left after TRIM, they are probably non-breaking spaces (character 160). Google’s TRIM help page says non-breaking spaces will not be trimmed, and the same goes for Data › Data cleanup › Trim whitespace. Turn them into normal spaces first: =TRIM(SUBSTITUTE(A2, CHAR(160), " ")).

How do I remove line breaks inside a cell in Google Sheets?

Replace the line break character, CHAR(10), with a space and trim the result: =TRIM(SUBSTITUTE(A2, CHAR(10), " ")). CLEAN also removes line breaks, but it removes them without leaving a space, so "Eli" and "Moss" on two lines become "EliMoss".

Is there one formula that removes all extra whitespace?

=TRIM(REGEXREPLACE(SUBSTITUTE(A2, CHAR(160), " "), "\s+", " ")) turns non-breaking spaces into normal spaces, turns every run of spaces, tabs and line breaks into one space, then trims the ends. REGEXREPLACE only works with text, so use it on text columns such as names and emails.

How can I tell if a cell has hidden spaces?

Compare lengths: =LEN(A2)-LEN(TRIM(A2)) returns how many spaces TRIM would remove, and LEN counts every character, including spaces and non-printing characters. To identify a character, =CODE(MID(A2, 4, 1)) returns the code of the 4th character: 32 is a normal space, 160 a non-breaking space and 10 a line break.

Do extra spaces stop Google Sheets from finding duplicates?

Yes. COUNTIF checks each cell for equality, so "ana@example.com " with a trailing space and "ana@example.com" are counted as different values, and EXACT requires identical spaces and hidden characters. Clean the column first, then count or remove duplicates.

Clean a column without helper formulas? SheetDupes (disclosure: we make it) is a Google Sheets add-on for duplicate rows and messy contact data. Select any cell in the column and choose Extensions › SheetDupes › Standardize › Trim extra spaces. It turns every run of spaces, non-breaking spaces, tabs and line breaks in that column into a single space and removes them from both ends of each cell, after copying a backup tab. Standardize refuses a sheet that contains formulas, so run it on the raw data, not next to helper columns. When it compares rows to find duplicates, it does the same cleanup on the fly: any run of spaces, non-breaking spaces, tabs and line breaks counts as one space and is ignored at the ends of a cell, and letter case is ignored too unless you tick Match case (email columns always ignore case). So on the raw example above it pairs rows 2 and 4, 3 and 7, 6 and 9, and 8 and 11 without any cleanup first. Preview and Highlight are free on any size sheet; there is a 14-day free trial with no credit card, and writes remain free after the trial on sheets with up to 2,000 data rows during launch (through Jan 31, 2027; 500 after that). It only reads and writes the spreadsheet you have open, and your data is not sent to Loomwise. It is live on the Google Workspace Marketplace.
Install free from Google Workspace MarketplaceSee SheetDupes
Want to test it first? Try it on sample data (makes a copy of a 12-row example sheet in your Drive).

Related guides