Remove Spaces

 

The TRIM function in Excel removes leading spaces, extra spaces and trailing spaces. Use the SUBSTITUTE function to remove all spaces or non-breaking spaces.

1. The TRIM function below removes 2 leading spaces, 3 extra spaces and 2 trailing spaces.

Remove Spaces in Excel

Note: the TRIM function does not remove single spaces between words.

2. To get the length of a string, use the LEN function.

Len Function

Explanation: the LEN function counts 2 spaces, 2 characters, 4 spaces, 3 characters and 2 spaces.

3. You can use the SUBSTITUTE function to remove all spaces.

Remove All Spaces

Note: the SUBSTITUTE function substitutes spaces (second argument) with empty strings (third argument).

Text imported from other applications may contain ASCII characters. The CLEAN function removes the first 32 non-printable ASCII characters (codes 0 through 31).

4. The CLEAN function below removes a non-printable character, CHAR(7).

Clean Function

5. Simply combine the CLEAN and the TRIM function to remove non-printable characters and spaces.

Clean and Trim Function

6. The CLEAN function removes line breaks. To enter a line break, press ALT + ENTER.

Remove Line Breaks

7. You can also use the SUBSTITUTE function to remove a line break, CHAR(10), and replace it with something else. For example, a comma and a space.

Substitute Line Breaks

The CLEAN function doesn't remove all ASCII characters. Simply use the SUBSTITUTE function to remove other ASCII characters.

8. First, find out the code number of the character.

Code Number

9. Next, use the SUBSTITUTE and the CHAR function to return the text string without this character.

Substitute Function

10. If your text contains non-breaking spaces, CHAR(160), the TRIM function doesn't work.

Non-breaking Spaces

11. You can use the SUBSTITUTE function to substitute non-breaking spaces, CHAR(160) with normal spaces, CHAR(32). Don't forget to add a TRIM function to remove the extra spaces.

Remove Non-breaking Spaces