最佳答案
您可以使用正则表达式来完成此任务。
这里一个有用的正则表达式构造是 negated character class :您使用 [^...]
并在其中插入您不想匹配的范围。因此,要匹配 ASCII 字母、数字和连字符以外的字符,请使用 [^a-zA-Z0-9-]
。
并像这样使用它
Dim strPattern As String: strPattern = "[^a-z0-9-]"
Dim regEx As Object
Set regEx = CreateObject("VBScript.RegExp")
regEx.Global = True
regEx.IgnoreCase = True
regEx.Pattern = strPattern
For Each cell In ActiveSheet.Range("C:C") ' Define your own range here
If strPattern <> "" Then ' If the cell is not empty
If regEx.Test(cell.Value) Then ' Check if there is a match
cell.Interior.ColorIndex = 6 ' If yes, change the background color
End If
End If
Next
关于regex - 识别特殊字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40311253/