3 Ways to Remove Non-Alphanumeric Characters in Excel

Numbers, alphabets, and non-alphanumeric characters often get mixed up in huge volume of data and we often need to remove non-alphanumeric characters in Excel. In this article, you will get some idea about how you can remove such non-alphanumeric characters in Excel by 3 different approaches.


๐Ÿ“ Download Excel File

Download the practice workbook below.


What Are Non-Alphanumeric Characters?

Non-alphanumeric characters are any characters or symbols other than letters and numbers that may be typed on a computer keyboard. These special characters include punctuation and mathematical symbols. For example, # is a non-alphanumeric character.


Learn to Remove Non-Alphanumeric Characters in Excel with These 3 Approaches

Suppose you have some data where non-alphanumeric symbols are mixed with the alphabets and numbers and you want to get rid of such symbols. Solving this problem can be quite tricky and most of the time you might require a code to solve such a problem. In this article, we will be talking about the processes available to remove Non-Alphanumeric characters in Excel. The dataset we will be used to illustrate things clearly is as follows:

Remove non alphanumeric characters excel sample datasheet


Approach

1. Using SUBSTITUTE Function

We can use the SUBSTITUTE function in Excel to replace alphanumeric characters with empty strings. The syntax of the SUBSTITUTE Function is as follows:

SUBSTITUTE(text, old_text, new_text, [instance_num])

Text (Required) : The reference of the cell containing text which we want to replace.

Old_text (Required): The text we want to replace.

New_text (Required): The text we want to replace the old text with.

Instance_num (Optional): This specifies which instance of old text we want to replace with new_text.

We should remember that the SUBSTITUTE Function replaces one particular non-alphanumeric character. So, depending on the dataset we have to use the function multiple times if we need to do so. The steps for this process are as follows:

ย โฌ‡๏ธโฌ‡๏ธ STEPS โฌ‡๏ธโฌ‡๏ธ

  • We select cell C6.
  • After that, we hover over to the formula tab and write the following formula.
=SUBSTITUTE(SUBSTITUTE(B6,"*",""),"#","")ย 

๐Ÿ”จ Formula Breakdown

SUBSTITUTE(SUBSTITUTE(B6,โ€*โ€,โ€โ€),โ€#โ€,โ€โ€)

๐Ÿ‘‰ย  Here, B6 is the cell reference where we want to look for substituting value.

๐Ÿ‘‰ย  โ€*โ€ is the old text that we want to look for to replace.

๐Ÿ‘‰ย  โ€โ€ is the new blank text that we want to put instead of the previous character.

๐Ÿ‘‰ย  Since we want to replace both โ€œ*โ€ and โ€œ#โ€, we have to use a SUBSTITUTE Function inside another SUBSTITUTE Function and thereby replace old text โ€œ#โ€ with blank value โ€œโ€.

Remove non alphanumeric characters in excel by using the SUBSTITUTE Function 1

  • Now we go to the bottom right of cell C6 and drag the Fill Handle icon down to get the results for the other data.

  • The final image free of alphanumeric characters will look like the one below:

Remove non alphanumeric characters in excel by using the SUBSTITUTE Function

๐Ÿ“• Read More: 5 Ways to Remove Last Character from String in Excel


Approach

2. Applying User-Defined Function

We cannot use the SUBSTITUTE Function when we need to remove a large number of non-alphanumeric characters from a dataset. Let us include more alphanumeric characters inside the existing dataset and now take a different approach. In this approach, we will be making a user-defined function in the Developer section. The steps are as follows:

โฌ‡๏ธโฌ‡๏ธ STEPS โฌ‡๏ธโฌ‡๏ธ

  • We go to the Developer tabย and click on Visual Basic. Alternatively, we can press the shortcut key Alt+F11.

Remove non alphanumeric characters in excel by applying user defined function 1

  • We go to Insert and click on Module.

Remove non alphanumeric characters in excel by applying user defined function 2

  • A new Module will be created. We write the following code on the blank box on the right. Here, we have made a new function named RemoveNonAlphaNumericCharacters() and later called the function to filter the cell values from Non-Alphanumeric Characters.
Function RemoveNonAlphaNumericCharacters(str As String) As String
Dim strR As String
Dim cha As String
Dim strmd As String
Dim inte As Integer
strmd = "[A-Z.a-z 0-9]"
strR = ""
For inte = 1 To Len(str)
cha = Mid(str, inte, 1)
If cha Like strmd Then
strR = strR & cha
End If
Next
RemoveNonAlphaNumericCharacters = strR
End Function

Remove non alphanumeric characters in excel by applying user defined function 3

  • We run the code. Before it is executed, a pop-up box with the name Macro will come. We write a short form for User Defined Function as UDF and press Create.

Remove non alphanumeric characters in excel by applying user defined function 4

  • After that, the visual basic window will look like this.

  • Now we come back to cell C6 and write the following formula.
=RemoveNonAlphaNumericCharacters(B6)

  • The non-alphanumeric characters will be removed.
  • After that, we drag the Fill Handle icon down to get all the results.

  • The overall output will look like the following image:

Remove non alphanumeric characters in excel by applying user defined function

๐Ÿ“• Read More: 3 Ways to Remove Non-Numeric Characters from Cells in Excel


Approach

3. Executing VBA Code

Another approach to solving this problem is to insert a VBA code in the Visual Basic module in Excel. To demonstrate this approach, we need to follow these steps:

โฌ‡๏ธโฌ‡๏ธ STEPS โฌ‡๏ธโฌ‡๏ธ

  • First, we copy the contents of the Non-Alphanumeric Data Column present in cell range B6:B12 to the Clean Data Column in cell range C6:C12.

Remove non alphanumeric characters in excel by inserting VBA code 1

  • Then we select the cells C6:C12 and go to the Developer Options tab and select Visual Basic or alternatively press Alt+F11 as a shortcut.

Remove non alphanumeric characters in excel by inserting VBA code 2

  • A new window will appear. We go to Insert and then click on Module.

Remove non alphanumeric characters in excel by inserting VBA code 3

  • In Module 2, we write the following VBA Code.
Sub VBAtoRemoveNonAlphanumericCharacters()
Dim R As Range
Dim WR As Range
On Error Resume Next
yTitleId = "Non-alphanumericcharactersremove"
Set WR = Application.Selection
Set WR = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
For Each R In WR
yOut = ""
For i = 1 To Len(R.Value)
yTemp = Mid(R.Value, i, 1)
If yTemp Like "[a-z.]" Or yTemp Like "[A-Z.]" Or yTemp Like "[0-9.]" Then
yStr = yTemp
Else
yStr = ""
End If
yOut = yOut & yStr
Next i
R.Value = yOut
Next
End Sub
  • We Run the code or press the F5 shortcut to run the code.

  • A popup box of Macros will appear. We select the Macro name as shown in the picture and press Run.

  • The results will turn out like the image shown below.

Remove non alphanumeric characters in excel by inserting VBA code


๐Ÿ“„ Important Notes

๐Ÿ–Š๏ธย  If we cannot find the Developer tab, we can activate it by going to Customized Quick Access Toolbar and then clicking More Commands. After that, we select Developer from Customize Ribbon and then press OK.

๐Ÿ–Š๏ธย  The SUBSTITUTE Function will basically not work on cases where we need to get rid of multiple non alphanumeric characters. We need to call the function as many times as there is the number of different non alphanumeric characters.

๐Ÿ–Š๏ธย  Creating a custom formula does not alter the structure of a worksheet or a cell. It has limitations.


๐Ÿ“ Takeaways from This Article

You have taken the following summed-up inputs from the article:

๐Ÿ“Œ ย We can use the SUBSTITUTE Function to get rid of non-alphanumeric characters but it has to be used as much as the number of individual non-alphanumeric character present.

๐Ÿ“Œย  Custom Formulas can also remove non-alphanumeric characters and we can call such functions anytime after creating one.

๐Ÿ“Œย  Finally, using VBA Code is the most accepted form by which we can remove non-alphanumeric characters very easily.


Conclusion

In conclusion, I hope this article was able to provide you with insights to remove non-alphanumeric characters in Excel. If you have any queries regarding the topic, feel free to ask in the comment section. Visit our site Excelden to get more informative articles related to Excel.


Related Articles

(Visited 141 times, 1 visits today)
Abrar

Abrar

Hello there! I am Mohammad Abrar Uddin, an engineering graduate from BUET. I write articles and blogs related to Excel in this site and hope that the viewers can learn simple to complex solutions of Excel problems easily by reading such articles.

We will be happy to hear your thoughts

Leave a reply

ExcelDen
Logo