excel – 如何编写vba代码来删除和替换UTF8-Characters

我有这个代码,我似乎仍然无法用简单的“占位符”替换我的数据中的非英语字符,如越南语或泰语.

Sub NonLatin()
Dim cell As Range
    For Each cell In Range("A1", Cells(Rows.Count, "A").End(xlUp))
        s = cell.Value
            For i = 1 To Len(s)
                If Mid(s, i, 1) Like "[!A-Za-z0-9@#$%^&* * ]" Then cell.Value = "placeholder"
            Next
    Next
End Sub

感谢您的帮助

最佳答案 你可以替换任何超出e的字符. G.使用以下代码的占位符的ASCII范围(前128个字符):

Option Explicit

Sub Test()

    Dim oCell As Range

    With CreateObject("VBScript.RegExp")
        .Global = True
        .Pattern = "[^u0000-u00F7]"
        For Each oCell In [A1:C4]
            oCell.Value = .Replace(oCell.Value, "*")
        Next
    End With

End Sub
点赞