Deleting Special Characters

iamtheboss32

New Member
Joined
Apr 11, 2018
Messages
4
Hi Good Day everyone!


I have an excel file that needs to remove all special characters except for the following

1.)A-Z & a-z
2.) 0-9
3.), . - _ é É

I have found a vba code but I really cant update it cause I might break the file. This code only removes the characters under xChars. is there any way to reverse since characters that I want to retain are fewer than all special characters.

here is the code I found on google

Function RemoveSpecial(Str As String) As String
Dim xChars As String
Dim I As Long
xChars = "#$%()^*&"
For I = 1 To Len(xChars)
Str = Replace$(Str, Mid$(xChars, I, 1), "")
Next
RemoveSpecial = Str
End Function


Thanks,
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Code:
Public Function RemoveSpecial(inputString As String) As String

Const AllowedCharacters = "abcdefghijklmnopqrstuvwxyz0123456789,.-_é"

Dim i As Long

For i = 1 To Len(inputString)
    If InStr(1, AllowedCharacters, Mid$(inputString, i, 1), vbTextCompare) > 0 Then
        RemoveSpecial = RemoveSpecial & Mid$(inputString, i, 1)
    End If
Next i

End Function

WBD
 
Upvote 0
Code:
Public Function RemoveSpecial(inputString As String) As String

Const AllowedCharacters = "abcdefghijklmnopqrstuvwxyz0123456789,.-_é"

Dim i As Long

For i = 1 To Len(inputString)
    If InStr(1, AllowedCharacters, Mid$(inputString, i, 1), vbTextCompare) > 0 Then
        RemoveSpecial = RemoveSpecial & Mid$(inputString, i, 1)
    End If
Next i

End Function

WBD


Thanks for the reply. just wondering I am going to add this on my module or should I create a new module for this. Sorry this is my 1st time to use VBA. really have limited knowledge in understanding the codes.
 
Upvote 0
Hey. Use [Alt]+[F11] to open the VBA editor and the Insert->Module. Paste the above function into that module. You can then use it in a cell on the sheet like this:

Code:
=RemoveSpecial(A1)

WBD
 
Upvote 0
Hey. Use [Alt]+[F11] to open the VBA editor and the Insert->Module. Paste the above function into that module. You can then use it in a cell on the sheet like this:

Code:
=RemoveSpecial(A1)

WBD

Thaks a lot It is now working. I think I need to enroll myself on an advance class for excel. Thanks again!!!
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,689
Members
449,117
Latest member
Aaagu

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