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 techguruplus telegram group Join Our WhatsApp Group techguruplus whatsapp group
Nazim Khan - Author Image

Nazim Khan (Author) 📞 +91 9536250020
[MBA in Finance]

Nazim Khan is an expert in Microsoft Excel. He teaches people how to use it better. He has been doing this for more than ten years. He is running this website (TechGuruPlus.com) and a YouTube channel called "Business Excel" since 2016. He shares useful tips from his own experiences to help others improve their Excel skills and careers.

Leave a Comment