Re: "It leaves the trailing spaces"

Most likely those spaces are Character 160 (called a non-breaking space).

This formula removes almost all unnecessary characters...

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

This formula gets just the non-breaking spaces...

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

The 'Clean Data' utility in my free "Professional_Compare" workbook will do

it for you without having to use a helper column.

Download from OneDrive...

https://1drv.ms/u/s!Au8Lyt79SOuhZw2MCH7_7MuLj04?e=sAwbHU

'---

Nothing Left to Lose

Discussions

Trim function not working on trailing space
I have a list of Employee numbers (varying from 4-6 digits) and they have a trailing space on all of them. I have tried the Trim function, and find/replace but nothing will remove the space. I have tried formatting them as General, Numbers and Text but I cannot get the space removed. More on mrexcel.com
🌐 mrexcel.com
5
0
February 1, 2024
Trim function is not removing multiple spaces within a string
I am pulling my hair out over this one. I have a name that should be LastName1(space)LastName2(comma)(space)FirstName Example: De Lahoya, Oscar For some reason the Trim function 'apparently' is leaving two spaces between the two last names. Sub PeskyName() ' Dim PeskyName As String '... More on mrexcel.com
🌐 mrexcel.com
6
0
August 30, 2021
excel trim function is removing spaces in middle of text - this was unexpected (?) - Stack Overflow
The excel trim function is removing spaces in middle of text - this was unexpected (?) i.e. I thought that the excel trim was for trimming leading and trailing spaces. e.g. a cell value of =Trim("L... More on stackoverflow.com
🌐 stackoverflow.com
excel - Trim Command Not Working - Stack Overflow
Hello Every One, I am trying to trim some data in excel column but leading spaces are not removed and hence vlookup function is also not matching the data properly due to the leading More on stackoverflow.com
🌐 stackoverflow.com
🌐
Trump Excel
trumpexcel.com › home › excel vba trim function (explained with examples)
Excel VBA TRIM Function (explained with Examples)
September 4, 2018 - As you can see in the message box result, the extra spaces between words are not removed by the VBA TRIM function. ... If you want to remove leading, trailing, as well as double spaces in between words, it’s better to use the following code:
🌐
ExcelHelp
excelhelp.com › home › general vba › excel trim vba function
Excel TRIM VBA Function: Remove Leading and Trailing Spaces | Excel Help
May 23, 2020 - The Excel TRIM VBA function is important to use when you are working with data derived from locations where there could be leading and trailing spaces.
🌐
Excel Forum
excelforum.com › excel-formulas-and-functions › 1408975-cannot-remove-trailing-spaces.html
Cannot remove trailing spaces [SOLVED]
Hi Spitfire47 Problem is that it is not what it seems, the first character is not a space, but something else char(160). to be solved like this: =VALUE(TRIM(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($C3,",",""),CHAR(160),""),".",","))) cheers · I started learning VBA because I was lazy ...
🌐
Excel Insider
excelinsider.com › home › our blog › excel pro tips › how to remove trailing spaces in excel (3 effective ways)
How to Remove Trailing Spaces in Excel (3 Effective Ways) - Excel Insider
June 6, 2026 - ➤ Select the range of cells you want to clean. For example, A2:A11. ➤ Press Alt + F8 , choose RemoveSpaces, and click Run. ➤ Excel will instantly remove all trailing and leading spaces from the selected cells.
Find elsewhere
🌐
Excelmaster
excelmaster.ai › blog › vba-trim
VBA Trim in Excel — Why It Doesn't Remove Your Spaces (and the Chr(160) Fix)
June 10, 2026 - It does not collapse double spaces inside the text, and it does not remove the non-breaking space (Chr(160)) that web pages and PDFs paste in. That second fact is why "Trim didn't work" is one of the most-searched VBA complaints. Sub TrimDemo() Dim s As String s = " Acme Corp " ' ends + a DOUBLE space in the middle Debug.Print "[" & Trim(s) & "]" ' [Acme Corp] <- ends gone, inner double space STAYS Debug.Print "[" & LTrim(s) & "]" ' [Acme Corp ] left side only Debug.Print "[" & RTrim(s) & "]" ' [ Acme Corp] right side only End Sub
🌐
Lifewire
lifewire.com › when-excels-trim-function-doesnt-work-3123658
Use This Alternate Formula When Excel's TRIM Function Doesn't Work
June 15, 2020 - The ASCII code for a non-breaking space is 160. The ASCII code for a regular space is 32. The TRIM() function can only remove spaces that have an ASCII code of 32.
🌐
MrExcel
mrexcel.com › forums › question forums › excel questions
Trim function is not removing multiple spaces within a string | MrExcel Message Board
August 30, 2021 - Click to expand... Crap! I falied to read the fine print. ... There is one important thing to know when using the TRIM function in VBA – it will only remove the leading and trailing spaces.
🌐
WPS Office
wps.com › blog › how-to-fix-excel-trim-function-not-working
How to Fix Excel TRIM Function Not Working (A Easy Way)
June 1, 2026 - Argument: Ensure you're providing the correct argument (text) to the TRIM function · I found this method to be the most effective way to remove leading and trailing spaces in Excel. However, it can be a bit tricky to get the syntax right.
🌐
Wall Street Mojo
wallstreetmojo.com › home › all blogs › vba resources › vba trim
VBA TRIM Function | How to use Excel VBA TRIM Function?
December 23, 2024 - However, selecting and clicking on the rectangular shape will only remove trailing and leading spaces, not in-between spaces. To overcome this problem, we need to use the Trim function as a worksheet function in the code.
🌐
Wellsr
wellsr.com › vba › 2016 › excel › improve-vba-rtrim-to-remove-trailing-spaces-excel
Improve VBA RTrim to Remove Trailing Spaces in Excel - wellsr.com
November 4, 2016 - For whatever reason, now you want to only remove trailing spaces, but not all trailing whitespace characters. You would do that by entering TRUE for the optional argument. Here’s how it looks on Row 5: By including TRUE in the optional argument, ...
🌐
Stack Overflow
stackoverflow.com › questions › 43442676 › trim-command-not-working
excel - Trim Command Not Working - Stack Overflow
Hey @Slai , no, TRIM doesn't remove spaces between characters, only leading and trailing spaces.
🌐
Microsoft Learn
learn.microsoft.com › en-us › office › vba › language › reference › user-interface-help › ltrim-rtrim-and-trim-functions
LTrim, RTrim, and Trim functions (Visual Basic for Applications) | Microsoft Learn
September 13, 2021 - It uses the Trim function to strip both types of spaces. Dim MyString, TrimString MyString = " <-Trim-> " ' Initialize string. TrimString = LTrim(MyString) ' TrimString = "<-Trim-> ". TrimString = RTrim(MyString) ' TrimString = " <-Trim->". TrimString = LTrim(RTrim(MyString)) ' TrimString = "<-Trim->". ' Using the Trim function alone achieves the same result. TrimString = Trim(MyString) ' TrimString = "<-Trim->". ... Have questions or feedback about Office VBA or this documentation?
🌐
ExtendOffice
extendoffice.com › documents › excel › how to remove trailing spaces from cells in microsoft excel?
How to remove trailing spaces from cells in Microsoft Excel?
October 8, 2024 - VBA code: Remove all trailing spaces from selected cells in Excel · Sub NoSpaces() 'Update by Extendoffice 20180613 Dim c As Range For Each c In Selection.Cells c = Trim(c) Next End Sub
🌐
MrExcel
mrexcel.com › forums › question forums › excel questions
Remove trailing spaces without losing middle spaces | MrExcel Message Board
September 29, 2017 - Welcome to the Board! Excel VBA has RTRIM, which only removes spaces from the end. However, there is no native Excel function that does that.
🌐
Ablebits
ablebits.com › ablebits blog › excel › excel formulas › how to remove blank spaces in excel - leading, trailing, non-breaking
How to remove blank spaces in Excel - leading, trailing, non-breaking
March 20, 2023 - You can find, extract, compare, delete, or replace strings that match the regular expression pattern you enter. You don't need to install any VBA code. ... I have an interesting issue which non of the above addresses. I have only one part number in a column which has three trailing spaces which TRIM, CLEAN, and SUBSTITUTE (including CHAR()) does not remove in formula.