visual basic excel中的基本语法错误
我想用这个macros删除非字母数字字符。
这个简单的程序给我一个语法错误。
我根本不明白这个错误。
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
你有&
这是无效的语法。 将其更改为:
strResult = strResult & Mid(strSource, i, 1)