代码使用.address不执行代码,尽管它运行没有错误

时间:2016-03-14 17:41:35

标签: excel vba excel-vba

我无法弄清楚Sub RemoveC

中缺少什么

该函数工作正常,因为我可以将其称为单个列但我想在整个工作表上运行它并且address非常快

代码运行但没有任何反应,不确定我需要更改什么以便我使用.address

由于

Sub RemoveC()
Dim ws As Worksheet

For Each ws In Worksheets(Array("X", "Y"))
    With ws.UsedRange.Offset(1, 0)

       removeChars " & .Address & "

    End With
Next ws
End Sub

功能:

Function removeChars(ByVal strSource As String) As String
Dim strResult As String
Dim i As Long

For i = 1 To Len(strSource)
    Select Case Asc(Mid(strSource, i, 1))
        Case 0, 9, 10, 12, 33, 48 To 57, 126 To 255:

        Case Else:
            strResult = strResult & Mid(strSource, i, 1)

    End Select
Next i

removeChars = strResult

End Function

1 个答案:

答案 0 :(得分:1)

要将此功能应用于单元格的内容,请将removeChars " & .Address & "更改为.Value = removeChars(.Text)