remove non alphanumeric from a cell

Flicker

New Member
Joined
Feb 19, 2009
Messages
45
Hi,

I want to remove non alphanumeric character from a cell.

From To
A@@@@BC ABC
A B123**D AB123D

alphanumeric character that I want to keep are a-z A-Z and 0-9

As far as I check, substitute function limit to replace only 1 character at a time.

multiple substitute function limited up to 8 time.

The question are;

1. How to apply "OR" in SUBSTITUTE function?

2. are there any function "NOT IN" and kick those character out?

Thanks :D
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hi,

You could try this UDF:

Code:
Function removeSpecial(sInput As String) As String
    Dim sSpecialChars As String
    Dim i As Long
    sSpecialChars = "\/:*?@""<>|"
    For i = 1 To Len(sSpecialChars)
        sInput = Replace$(sInput, Mid$(sSpecialChars, i, 1), "")
    Next
    removeSpecial = sInput
End Function

Add more special chars to the list as required.
 
Upvote 0
Solution
Hello

Try this.
Excel Workbook
AB
1A@@@@BCABC
2A B123**DAB123D
Sheet1
Excel 2010
Cell Formulas
RangeFormula
B1=Remove(A1)


Code:
Private RX As Object

Private Sub CreateRX()
    Set RX = CreateObject("VBScript.RegExp")
End Sub

Function Remove(ByVal s As String) As String
    If RX Is Nothing Then CreateRX
    With RX
        .Pattern = "[^0-9A-Za-z]"
        .Global = True
        Remove = .Replace(s, "")
    End With
End Function
 
Last edited:
Upvote 0
Here's another UDF.
Rich (BB code):
Function CleanText(ByVal Text As String) As String
Static REX As Object '<--- RegExp
    
    If REX Is Nothing Then Set REX = CreateObject("VBScript.RegExp")
    With REX
        .Global = True
        .Pattern = "[^a-zA-Z0-9]"
        CleanText = .Replace(Text, vbNullString)
    End With
End Function
 
Upvote 0

Forum statistics

Threads
1,224,618
Messages
6,179,917
Members
452,949
Latest member
beartooth91

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top