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:

=SUBSTITUTE(B1,”-”,””)

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, "-", "")
    Next
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])….

Leave a Reply