Replace Spaces with a Dash or Underscore in Excel [Video]

The other day someone in my Excel course asked if there was a way to quickly replace all of the spaces in a group of cells with dashes or underscore characters.

One of Excel’s hidden strengths is its ability to manipulate data.

There are 3 ways to replace spaces with a dash or underscore character. Read on to become a master manipulator… of data in Microsoft Excel!

If, instead of replacing spaces with a dash or underscore, you’d like to remove them altogether, check out this article on how to remove spaces from words or numbers in Excel.

Replace Spaces with Find and Replace

Using Find and Replace is one way to selectively update information in an Excel worksheet.

Here is what you need to do.

  1. Select the range of cells that you would like to update.
  2. Press Ctrl + H to display the Find and Replace dialog box or click the Find & Select button in the Home > Editing group, then select Replace.
  3. Type a space in the Find what: box then press Tab to move down one field.
  4. Type an underscore character (_) in the Replace with: box.
  5. Click Replace All.
Replace spaces with the find and replace dialog box

Replace Spaces Using the SUBSTITUTE Function

The SUBSTITUTE function can be used to replace one string of characters with another. In this example, we’ll replace the spaces between words with an underscore character.

Replace spaces with a dash or underscore in Excel

Before we get started, let’s look at how the SUBSTITUTE function works.

SUBSTITUTE Function Syntax

Here is the syntax of the SUBSTITUTE function:


  • Text is the cell address containing the text you want to update.
  • Old_text is the existing character (a space).
  • New_text is the revised text (an underscore).
  • Instance_num identifies which instance of Old_text should be updated. If this parameter is omitted, all instances of Old_text are updated.

In the example, below, the SUBSTITUTE function was used to replace spaces with underscore characters. Cell E8 is highlighted for your reference.

Replace spaces using the SUBSTITUTE function

Replace Spaces Using Flash Fill

Flash Fill has been included with every new version of Excel since its release with Excel 2013. If you’ve never used this feature, you’re going to love it!

  1. Click to the right of an existing cell with text containing spaces.
  2. Carefully type the cell’s content with an underscore in place of any spaces you’d like to remove, then press Enter.
  3. Type the first letter of the text in the next row then press Enter to let Flash Fill complete the remaining entries.
Replace spaces using Flash Fill

Work Smarter, Not Harder!

I hope these 3 techniques for replacing spaces with a dash or underscore have saved you a little work. In my experience, any time spent learning more efficient ways to complete common tasks in Microsoft Excel will pay off tenfold!

If you’ve enjoyed this article, there are plenty of other shortcuts you can learn about in Excel!

By Michael Belfry

Working as a full-time training consultant, Michael provides Microsoft Office courses to government and private sector clients across Canada.