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
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
Your advice worked perfectly. Thanks. I though it probably had to do with hard spaces, but I did not know how to get rid of them.
excel - Trim function and WorksheetFunction.Trim do not remove leading or trailing spaces - Stack Overflow
Trim Function Not Behaving as Expected
excel - Trim Command Not Working - Stack Overflow
string - Trim not removing white spaces? - Stack Overflow
I have a sheet of names where there are single space, double space, triple spaces at the beginning of the data. TRIM function only works on single spaces and TEXT TO COLUMN isnt ideal as the spaces vary in different cells. What is the cure.
Edit:Thanks everyone for ur help.
Quite often the issue is a non-breaking space - CHAR(160) - especially from Web text sources -that CLEAN can't remove, so I would go a step further than this and try a formula like this which replaces any non-breaking spaces with a standard one
=TRIM(CLEAN(SUBSTITUTE(A1,CHAR(160)," ")))
Ron de Bruin has an excellent post on tips for cleaning data here
You can also remove the CHAR(160) directly without a workaround formula by
- Edit .... Replace your selected data,
- in Find What hold
ALTand type0160using the numeric keypad - Leave Replace With as blank and select Replace All
If you would like to use a formula, the TRIM function will do exactly what you're looking for:
+----+------------+---------------------+
| | A | B |
+----+------------+---------------------+
| 1 | =TRIM(B1) | value to trim here |
+----+------------+---------------------+
So to do the whole column...
1) Insert a column
2) Insert TRIM function pointed at cell you are trying to correct.
3) Copy formula down the page
4) Copy inserted column
5) Paste as "Values"
Should be good to go from there...