Removing Dash Characters in Excel

This post will guide you how to remove all dash characters from a text string in one cell in Excel. How to remove dashes from social security numbers in a cell with a formula in Excel.

Removing Dash Characters

If you want to remove all dash characters in one cell in Excel, you can use a formula based on the SUBSTITUTE function.

For example, you want to remove dashes from text string in one cell (B1), you can write down the following formula:


You need to type this formula into a blank cell, and then press Enter key in your keyboard.

remove dash characters1

You will see that all dash characters in cell B1 has been removed.


Remove Dash Characters with VBA Code

You can also use an Excel VBA macro to remove all dash characters from text string in a range of cells in Excel. Just do the following steps:

#1 open your excel workbook and then click on “Visual Basic” command under DEVELOPER Tab, or just press “ALT+F11” shortcut.

Get the position of the nth using excel vba1

#2 then the “Visual Basic Editor” window will appear.

#3 click “Insert” ->”Module” to create a new module.

convert column number to letter3

#4 paste the below VBA code into the code window. Then clicking “Save” button.

remove dash characters2

Sub RemoveDashChar()
    Dim R As Range
    Dim myRange As Range
    Set myRange = Application.Selection
    Set myRange = Application.InputBox("Select one Range that you want to remove dashes", "removedashchar", myRange.Address, Type:=8)
    For Each R In myRange
        R.Value = VBA.Replace(R.Value, "-", "")
End Sub

#5 back to the current worksheet, then run the above excel macro. Click Run button.

remove dash characters3

#6 select one range that you want to remove dash characters

remove dash characters4

#7 let’s see the result.

remove dash characters5

Related Functions

  • Excel Substitute function
    The Excel SUBSTITUTE function replaces a new text string for an old text string in a text string.The syntax of the SUBSTITUTE function is as below:= SUBSTITUTE  (text, old_text, new_text,[instance_num])….
Related Posts

Find and Replace Multiple Values

This post will guide you how to find and replace multiple values at once with VBA macro or using formula  in Excel. How do I make multiple find and replace in Excel. Suppose that you have a few cells containing ...

VBA Macro For VLOOKUP From Another Sheet

In the previous post, you should know that how to fix or remove the #N/A error when using VLOOKUP formula to lookup value from another sheet. And this post will show you how to use VBA code to vlookup data ...

How To Insert Comments in Protected Worksheet in Excel

This post will show you how to allow comments in a protected worksheet in Excel. You can easily to insert comments into cells in a normal worksheet in Excel, but if want to insert a comment in a worksheet that ...

How To Convert Text to Upper Cases(Using VBA) in Excel

This post will show you how to switch from lower case to upper case in Excel. and I am going to show you two different ways of converting text to upper cases using formula or VBA macro in Excel 2013,Excel ...

How To Hide Every Other Row in Excel (Using VBA)

This post will show you how to hide alternate rows or columns in Excel or how to hide every third, fourth, fifth row or column in Excel. If you want to hide every other row in your current worksheet, how ...