How do I remove leading or trailing spaces of all cells in an entire column?
The worksheet's conventional Find and Replace
(aka Ctrl+H) dialog is not solving the problem.
How do I remove leading or trailing spaces of all cells in an entire column?
The worksheet's conventional Find and Replace
(aka Ctrl+H) dialog is not solving the problem.
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
ALT
and type 0160
using the numeric keypadIf 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...
Without using a formula you can do this with 'Text to columns'.
The 'side-effect' is that Excel has removed all trailing spaces in the original column.
I've found that the best (and easiest) way to delete leading, trailing (and excessive) spaces in Excel is to use a third-party plugin. I've been using ASAP Utilities for Excel and it accomplishes the task as well as adds many other much-needed features. This approach doesn't require writing formulas and can remove spaces on any selection spanning multiple columns and/or rows. I also use this to sanitize and remove the uninvited non-breaking space that often finds its way into Excel data when copying-and-pasting from other Microsoft products.
More information regarding ASAP Utilities and trimming can be found here:
http://www.asap-utilities.com/asap-utilities-excel-tools-tip.php?tip=87