Remove Alpha Special Characters From Range Using Excel VBA
Remove Alpha Special Characters From Range Using Excel VBA
VBA Remove Alpha Special characters from Range helps to remove unwanted characters and numbers from a
selected Range . For example, user has to enter the non alphanumeric characters in a Cell or range. We need to
do data validation whether user enters non alphanumeric or not.If user enters also, we need remove those alpha
characters from cells using excel VBA.
Solution
Example Cases
o Remove Alpha Special characters – Using Procedure
Code
Output
Instructions
o Remove Alpha Special characters – Using Function
Code
Output
Instructions
Following is the example to Remove Alpha Special characters from cells in a selected Range using Excel VBA.
Code:
'Remove All Alpha and Special characters from cell or Range using VBA code
Sub Remove_AlphaCharacters_From_Cell_Or_Range()
'Variable Declaration
Dim iCnt As Integer
Dim IpData As Range, DataRange As Range
Dim sData As String, sTmp As String
'Create Object for Selected Range
On Error Resume Next
Set DataRange = Sheets("Sheet1").Range("A2:A10")
End Sub
Output:
Instructions:
Following is the one more example to Remove Alpha Special characters from cells in a selected Range using
user defined function with Excel VBA.
Code:
'Remove All Alpha and Special characters from cell
Function Remove_AlphaSpecialChar(DataCell As Range) As String
'Variable Declaration
Dim iCnt As Integer
Dim IpData As Range
Dim sData As String, sTmp As String
Remove_AlphaSpecialChar = sData
End Function
Output:
Here is the screenshot for showing User defined function to remove Alpha and Special Characters from the
cells.
Instructions: