Clean Blank Spaces in Excel: 4 Easy Ways to Do It
In this article
To clean blank spaces in Excel, you can use the TRIM function to remove extra spaces, the Find and Replace tool to delete all spaces, or the Go To Special feature to remove entirely empty rows and columns. Depending on whether you are dealing with leading/trailing spaces, double spaces between words, or completely empty cells, the method you choose will differ.
What You'll Need
- A computer with Microsoft Excel installed (works on Windows and macOS).
- A dataset containing inconsistent spacing or empty cells.
- A backup copy of your data (recommended before performing bulk deletions).
Step-by-Step
Depending on your goal, choose one of the following four methods. Note that menu labels may differ slightly depending on your version of Excel or region.
Method 1: Removing Extra Spaces with the TRIM Function
The TRIM function is the safest way to clean data because it removes all leading and trailing spaces and reduces multiple spaces between words to a single space. It does not delete the cells themselves, but cleans the text within them.
- Click on an empty cell adjacent to the data you want to clean.
- Type the formula
=TRIM(A2), replacing "A2" with the cell reference of the text you want to clean. - Press Enter to apply the formula.
- Hover your mouse over the bottom-right corner of the cell until the cursor turns into a small black cross (the fill handle).
- Click and drag the fill handle down to apply the formula to the rest of the column.
- To replace the original messy data with the clean data, select the new column and press Ctrl + C (Cmd + C on Mac) to copy.
- Right-click on the original column, select Paste Special, and choose Values. This removes the formula and keeps only the cleaned text.
- Delete the helper column used for the TRIM function.
Method 2: Deleting All Spaces using Find and Replace
Use this method if you need to remove every single space in a cell (for example, cleaning up phone numbers, ID codes, or SKU numbers where no spaces should exist).
- Select the range of cells or the entire column that contains the spaces you want to remove.
- Press Ctrl + H (Cmd + Shift + H on Mac) to open the Find and Replace dialog box.
- In the "Find what" field, press the Spacebar once. This tells Excel to look for a single blank space.
- Leave the "Replace with" field completely empty. Do not type anything, not even a space.
- Click Replace All.
- Excel will notify you of how many replacements were made. Click OK and close the dialog box.
Method 3: Removing Entirely Blank Rows or Columns
If your "blank spaces" are actually empty rows or columns that are breaking up your data, the Go To Special tool is the fastest way to purge them.
- Highlight the area of your spreadsheet that contains the blank rows.
- On the Home tab, go to the Editing group, click Find & Select, and choose Go To Special.
- In the dialog box that appears, select the radio button for Blanks and click OK. Excel will now highlight only the empty cells within your selection.
- While those blank cells are selected, stay on the Home tab and go to the Cells group.
- Click the arrow next to Delete and select Delete Sheet Rows.
- The empty rows will disappear, and the data below will shift up to fill the gaps.
Method 4: Using the CLEAN Function for Non-Printable Characters
Sometimes, "blank spaces" aren't actually spaces; they are non-printable characters (like line breaks or tab characters) often found in data imported from the web or external databases.
- Click in an empty cell next to your data.
- Type the formula
=CLEAN(A2), replacing "A2" with your target cell. - Press Enter and drag the fill handle down to apply it to the column.
- For maximum effectiveness, combine this with TRIM by nesting them:
=TRIM(CLEAN(A2)). This removes both non-printable characters and extra spaces in one step. - Copy the results and Paste Special as Values over the original data.
Common Mistakes
- Forgetting to Paste as Values: A common error when using TRIM or CLEAN is deleting the original data before converting the formulas to values. If you delete the source cell, the formula will return a #REF! error because it no longer has data to reference.
- Using Find and Replace on Sentences: If you use Method 2 (Find and Replace) on a column of full names or addresses, it will remove the spaces between words (e.g., "John Doe" becomes "JohnDoe"). Only use this for codes, IDs, or single-word entries.
- Selecting the Entire Sheet for "Go To Special": If you select the entire worksheet and delete blanks, you might accidentally delete thousands of empty rows at the bottom of your sheet, which can occasionally cause Excel to lag or behave unexpectedly. Only select the specific range containing your data.
- Ignoring Non-Breaking Spaces: Sometimes, data from websites uses a "non-breaking space" (char 160) which the TRIM function cannot see. If TRIM doesn't work, you are likely dealing with these special characters.
Tips
- Use a Helper Column: Always perform cleaning operations in a new column first. This allows you to compare the "Before" and "After" to ensure no critical data was accidentally deleted.
- Keyboard Shortcuts: To speed up the process of selecting data, use Ctrl + Shift + Down Arrow to select everything from your current cell to the bottom of the dataset.
- Data Validation: Once your data is clean, consider using Data Validation (Data tab > Data Validation) to prevent users from entering leading or trailing spaces in the future.
- The Power Query Alternative: For massive datasets (thousands of rows), use Power Query. Go to Data > Get Data, then use the "Transform" tab to select "Trim" or "Clean" from the Format menu. This is more efficient than formulas for big data.
Troubleshooting
If you have followed the steps but the blank spaces are still there, try these solutions:
- TRIM isn't working: This usually happens because the "space" is actually a non-breaking space (HTML character ). To fix this, use Find and Replace. In the "Find what" box, hold the ALT key and type 0160 on your numeric keypad, then leave "Replace with" empty and click Replace All.
- Go To Special doesn't find blanks: If a cell looks empty but isn't selected by "Go To Special," it likely contains a formula that is returning an empty string (
"") or a single hidden space. To fix this, use the TRIM function first, then try Go To Special again. - Excel freezes during Replace All: If you are working with a very large file, Replace All can cause the program to stop responding. Try selecting smaller chunks of data (e.g., 5,000 rows at a time) rather than the entire column.
- Data shifted incorrectly: If you deleted blank cells instead of blank rows, your data columns may now be misaligned. Press Ctrl + Z immediately to undo the action, and ensure you select "Delete Sheet Rows" instead of just "Shift cells up."
Frequently Asked Questions
Can I remove blank spaces using a macro?
Yes, you can write a VBA script to automate the TRIM function across multiple sheets. This is useful for recurring monthly reports where the data format is always the same.
Does the TRIM function remove spaces in the middle of a sentence?
No, TRIM only removes leading and trailing spaces. If there are multiple spaces between two words, it reduces them to one single space, but it will not remove the space entirely.
How do I remove blank rows without deleting data in other columns?
The safest way is to use a filter. Filter your data for "Blanks" in a primary column, select the resulting visible rows, right-click and delete, then clear the filter.
Is there a difference between a blank cell and an empty string?
Yes. A blank cell is truly empty (null). An empty string is a cell that contains a formula or a value that results in no visible text. "Go To Special > Blanks" only finds truly empty cells.
Can I use a formula to find if a cell has trailing spaces?
Yes, you can use a formula like =A2=TRIM(A2). If the result is FALSE, it means the cell contains extra spaces that need to be cleaned.