Leading and trailing spaces in Excel often leads to a lot of frustration. I can’t think of a situation where you may need these extra spaces, but it often finds its way into the excel spreadsheets. There are many ways you can end up with these extra spaces – for example, as a part of the data download from a database, while copying data from a text document, or entered manually by mistake. Leading, trailing, or double space between text could lead to a lot of serious issues. For example, suppose you have a data set as shown below:

Now have a look at what happens when I use a VLOOKUP function to get the last name using the first name.

You might not be able to spot the difference with the naked eye that there is an extra trailing space in the name that is causing this error.

In this example, it was easy to spot the issue in such a small data set, but imagine having to check this for thousands of records. To be on the safe side, it is always a good idea to clean your data and remove spaces in Excel.

How to Remove Spaces in Excel

In this tutorial, I will show you two ways to remove spaces in Excel.

Using TRIM function. Using Find and Replace.

Using the TRIM Function

Excel TRIM function removes the leading and trailing spaces, and double spaces between text strings. For example, in the above example, to remove spaces from the entire list if first names (in A2:A7), use the following formula in cell C1 and drag it down for all the first names: Excel TRIM function would instantly remove all the leading and trailing spaces in the cell. Once you have the cleaned data, copy it paste it as values in place of the original data.

This function is also helpful if you have more than one space character between words. It would remove the extra spaces such that the result always have one space character between words.

Excel TRIM function does a good job in removing spaces in Excel, however, it fails when you have non-printing characters (such as line breaks) in your data set. To remove non-printing characters, you can use a combination of TRIM and CLEAN functions. If you have some text in cell A1 from which you want to remove spaces, use the below formula: Non-printing characters can also result from =CHAR(160), which can not be removed by the CLEAN formula. So, if you want to be absolutely sure that you have all the extra spaces and non-printing characters, use the below formula:

Remove Extra Spaces in Excel using FIND and REPLACE

You can remove spaces in Excel using the Find and Replace functionality. This is a faster technique and can be useful in the given situations:

When you want to remove double spaces. When you want to remove all the space characters.

Removing Double Spaces

Note that this technique cannot be used to remove leading or trailing spaces. It will find and replace double spaces irrespective of its position. Here are the steps to do this:

Select the cells from which you want to remove double spaces. Go to Home –> Find & Select –> Replace. (You can also use the keyboard shortcut – Control + H). In the Find and Replace dialogue box, enter: Find what: Double Space. Replace with: Single Space. Click on Replace All.

This will replace all the double spaces with a single space character.

Note that this will only remove double spaces. If you have three space characters in between 2 words, it would result in 2 space characters (would remove one). In such cases, you can do this again to remove and any double spaces that might have been left.

Removing Single Spaces

To remove all the space characters in a data set, follow the below steps:

Select the cells from which you want to remove the space character. Go to Home –> Find & Select –> Replace. (You can also use the keyboard shortcut – Control + H). In the Find and Replace dialogue box, enter: Find what: Single Space. Replace with: Leave this blank. Click on Replace All.

This will remove all the space characters in the selected data set.

Note that in this case, even if there are more than one space characters between two text strings or numbers, all of it would be removed.

Remove Line Breaks

You can also use Find and Replace to quickly remove line breaks. Here are the steps to do this:

Select the data. Go to Home –> Find and Select –> Replace (Keyboard Shortcut – Control + H). In the Find and Replace Dialogue Box: Find What: Press Control + J (you may not see anything except for a blinking dot). Replace With: Leave it empty. Replace All.

This will instantly remove all the line breaks from the data set that you selected. Based on your situation, you can choose either method (formula or find and replace) to remove spaces in Excel. You may also like the following Excel tutorials:

Find and Remove Duplicates in Excel. 10 Super Neat Ways to Clean Data in Excel. MS Help – Remove Space and Non-printing characters. How to Remove the First Character from a String in Excel How to Remove Time from Date in Excel

=VLOOKUP(D2,$A$2:$B$7,2,0) Perfect example; however in your formula you refer to the 2nd column. Even if there were no leading spaces, the formula would still result in the #N/A error as “Bob” is in the 1st column. You might consider re-filming the gif to show your formula again i.e. =VLOOKUP(D2,$A$2:$B$7,1,0). Please forgive my assertion; I’m not trying to teach you to suck eggs, as I know you are a top Excel guru, just a typo. Best Josh