Remove leading or trailing spaces in an entire column of data

ExcelExcel FormulaExcel 2010

Excel Problem Overview


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.

Excel Solutions


Solution 1 - Excel

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 ALT and type 0160 using the numeric keypad
  • Leave Replace With as blank and select Replace All

Solution 2 - Excel

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...

Solution 3 - Excel

Without using a formula you can do this with 'Text to columns'.

  • Select the column that has the trailing spaces in the cells.
  • Click 'Text to columns' from the 'Data' tab, then choose option 'Fixed width'.
  • Set a break line so the longest text will fit. If your largest cell has 100 characters you can set the breakline on 200 or whatever you want.
  • Finish the operation.
  • You can now delete the new column Excel has created.

The 'side-effect' is that Excel has removed all trailing spaces in the original column.

Solution 4 - Excel

If it's the same number of characters at the beginning of the cell each time, you can use the text to columns command and select the fixed width option to chop the cell data into two columns. Then just delete the unwanted stuff in the first column.

Solution 5 - Excel

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[![enter image description here]2]2

Solution 6 - Excel

I was able to use Find & Replace with the "Find what:" input field set to:

> " * "

(space asterisk space with no double-quotes)

and "Replace with:" set to:

> ""

(nothing)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionvenkatView Question on Stackoverflow
Solution 1 - ExcelbrettdjView Answer on Stackoverflow
Solution 2 - Excelhydrox467View Answer on Stackoverflow
Solution 3 - ExcelJorisView Answer on Stackoverflow
Solution 4 - ExcelKatherine ChalmersView Answer on Stackoverflow
Solution 5 - ExcelJames MobergView Answer on Stackoverflow
Solution 6 - ExcelMr RomanView Answer on Stackoverflow