How to remove some special characters from string in Excel?
If there are some special characters such as %^&*() within the text strings, and now, you want to remove theses specific characters from the cell strings. To remove them one by one will be time-consuming, here, I will introduce some quick tricks for solving this task in Excel.
The following VBA code can help you to remove the specific characters you need, please do as follows:
1. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.
2. Click Insert > Module, and paste the following code in the Module Window.
VBA code: Remove some special characters from text string
Function RemoveSpecial(Str As String) As String 'updatebyExtendoffice 20160303 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
3. Then save and close this code, go back to the worksheet, and enter this formula: =removespecial(A2) into a blank cell where you want to put the result, see screenshot:
4. And then drag the fill handle down to the cells which you want to apply this formula, and all the special characters that you needn’t have been removed from the text string, see screenshot:
Note: In the above code, you can change the special characters #$%()^*& to any others that you want to remove.
If you are not skilled with the VBA code, Kutools for Excel’s Remove Characters utility can help you finish this task quickly and easily.
After installing Kutools for Excel, please so as follows:
1. Select the text strings that you want to remove some special characters.
2. Click Kutools > Text > Remove Characters, see screenshot:
3. In the Remove Characters dialog box, check Custom option under the Remove Characters section, and enter the special characters that you want to remove, see screenshot:
4. And then click Ok or Apply button, the characters you specified in the Custom textbox have been removed from the text strings at once, see screenshots:
Best Office Productivity Tools
Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time. Click Here to Get The Feature You Need The Most...
Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
- Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
- Open and create multiple documents in new tabs of the same window, rather than in new windows.
- Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!