Share via

Replace all special characters with space

Anonymous
2015-11-13T17:28:45+00:00

I have a string of data... A lot of the data is alphanumeric and many have special characters (!@#$%^&*()_+=-{}[]:;"'<>?,./~` ) 

Example: 6-ct of Apple-skins (#green)

I need to replace all special characters with spaces. 

6 ct of Apple skins  green

Prefer vba (16k+ rows of data) but formula would work as well.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

HansV 462.6K Reputation points
2015-11-13T18:44:51+00:00

You can run the following macro (select the range first):

Sub ReplaceSpecial()

    Dim cel As Range

    Dim strVal As String

    Dim i As Long

    Application.ScreenUpdating = False

    For Each cel In Selection

        strVal = cel.Value

        For i = 1 To Len(strVal)

            Select Case Asc(Mid(strVal, i, 1))

                Case 32, 48 To 57, 65 To 90, 97 To 122

                    ' Leave ordinary characters alone

                Case Else

                    Mid(strVal, i, 1) = " "

            End Select

        Next i

        cel.Value = strVal

    Next cel

    Application.ScreenUpdating = True

End Sub

Was this answer helpful?

3 people found this answer helpful.
0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2015-11-13T19:01:15+00:00

    Thanx!

    When I make my first million...

    I'm buying you a Krystal... WITH cheese!

    Was this answer helpful?

    0 comments No comments