0

I want to Remove Non-Alphanumeric Characters with this Macro.

this simple program gives me a syntax error.

I don't understand this error at all.

Sub CleanAll()
Dim rng As Range
Application.ScreenUpdating = False ' Turns off screen updating
On Error Resume Next ' Macro will continue if it encounters #N/A
'Adjust "Sheet1" and Range in Line 6
For Each rng In Sheets("Sheet1").Range("A2:A1629").Cells
    rng.Value = AlphaNumericOnly(rng.Value) ' Function call
Next
Application.ScreenUpdating = True
End Sub

Function AlphaNumericOnly(strSource As String) As String
Dim i As Integer
Dim strResult As String
On Error Resume Next
For i = 1 To Len(strSource)
Select Case Asc(Mid(strSource, i, 1))
'The numbers below match Char Codes to keep
 Case 48 To 57, 65 To 90, 97 To 122:
    strResult = strResult & Mid(strSource, i, 1)
End Select
Next
AlphaNumericOnly = strResult
End Function
1
  • strResult = strResult & Mid(strSource, i, 1) looks bad. Commented Dec 9, 2015 at 16:54

1 Answer 1

1

You have & which is not valid syntax. Change it to this:

strResult = strResult & Mid(strSource, i, 1)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.