How to remove trailing spaces from cells in Microsoft Excel?
Supposing you got an Excel worksheet from others, and you found that there are unwanted spaces at the end of the cells. And these trailing spaces are not easy to find out and affecting cell sorting, calculating, or other operations. This article will introduce several methods to remove trailing spaces from cells in Microsoft Excel as below screenshot shown.
Using the Trim function is easy to remove the trailing space in one cell, but time-consuming to remove trailing spaces in many cells. Here provides a macro to remove all trailing spaces of all cells in a selection.
1: Select the range you want to remove trailing spaces from cells.
2. Press the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.
3. Click Insert > Module, and paste the following macro in the Module Window.
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
4. Press the F5 key to run this macro. Then all trailing spaces are removed from cells of selected range immediately.
This section is going to introduce a handy addin - Kutools for Excel. Its Remove Spaces tool can help you remove all trailing spaces from cells quickly. Please do as follows
Before applying Kutools for Excel, please download and install it firstly.
1. Select the range you want to remove all trailing spaces from cells, then click Kutools > Text > Remove Spaces.
2. In the Remove Spaces dialog box, check the Trailing Spaces option in Spaces Type section and then click the OK button. See screenshot:
Then you can see all trailing spaces have been removed from selected cells immediately. See screenshot:
- Remove leading spaces in cells
- Remove spaces between character and numbers within cells
- Remove leading and trailing spaces
- Remove indents within cells
You are guest
or post as a guest, but your post won't be published automatically.
To post as a guest, your comment is unpublished.· 3 years agoTHANK YOU SO MUCH! I was going crazy doing a MS Word Mail merge from Excel data and couldn't figure out why there was extra space in the fields. MANY THANKS!
To post as a guest, your comment is unpublished.· 4 years agoRemove all white spaces after last character.
Ex. "CABLE AS " it should become "CABLE AS"
("" not there in the cell)
To post as a guest, your comment is unpublished.· 4 years agoYou Made my life, feeling excited thanks for this micro code. SUUUUUUUUUUUUUUPPPERRRRR
To post as a guest, your comment is unpublished.· 4 years agoYou might mention that you shouldn't select the entire worksheet as the range. It takes a very, very long time to process that many cells.
To post as a guest, your comment is unpublished.· 4 years agoAwesome! Thanks! Saved a lot of time!!
To post as a guest, your comment is unpublished.· 4 years agoWOW! Couldn't have been easier - thank you so much for the help!
To post as a guest, your comment is unpublished.· 5 years agoVery good. Saved me a lot of time, thanks!
To post as a guest, your comment is unpublished.· 5 years agoI solved it by copying the first formula in my 32 options I wanted to keep a part of the table, and pasted on the other 31 parts and the job was done.
To post as a guest, your comment is unpublished.· 5 years agoHello Frnds,
Need help to resolve a problem.
I have data in one single cell like as below:
(data is in single cell and having space in between). I want to just remove this breakline space and get the data in one single cell only as below:
Thanks in advance.
To post as a guest, your comment is unpublished.· 5 years agoGreat article. Is there a way to tie the VBA code to a button?
In order for the user to quickly hit and have the trailing spaces removed from a specific column.
To post as a guest, your comment is unpublished.· 6 years agoThanks for the macro to trim trailing spaces - easy, effective, and awesome.