VBA Code to Remove Special Characters from Cells in Excel

VBA Code:

' VBA Code to Remove Special Characters from Cells in Excel

Sub RemoveSpecialCharacters()
    Dim ws As Worksheet
    Dim rng As Range
    Dim cell As Range
    Dim specialChars As String
    Dim char As String
    Dim i As Integer
    
    ' Set the worksheet to work with
    Set ws = ThisWorkbook.Worksheets("Sheet1") ' Replace with the name of your worksheet
    
    ' Set the range of cells to remove special characters from
    Set rng = ws.UsedRange ' Modify to target a specific range if needed
    
    ' Define the special characters to remove
    specialChars = "!@#$%^&*()_+-={}[]|\:;'?/>.<,"
    
    ' Loop through each cell in the range
    For Each cell In rng
        ' Loop through each special character
        For i = 1 To Len(specialChars)
            char = Mid(specialChars, i, 1)
            ' Replace the special character with an empty string
            cell.Value = Replace(cell.Value, char, "")
        Next i
    Next cell
    
    ' Display a message
    MsgBox "Special characters have been removed from the cells."
End Sub


Check All VBA Codes

Join Our Telegram Group

Join the TechGuruPlus Telegram group

Join Our WhatsApp Group

Join the TechGuruPlus WhatsApp group
Nazim Khan, founder of TechGuruPlus.com

— Founder & Editor, TechGuruPlus.com
[MBA in Finance]

Nazim Khan has spent over ten years working with Excel, Tally and office documentation in accounts, finance and MIS roles. He has been running TechGuruPlus.com since 2016, where he publishes free editable templates for office work, and the YouTube channel Business Excel. He has trained more than 50,000 people online. Every template on this site is built and checked by him before it is published.

Contact  Â·  Excel Course

Leave a Comment