Dim reg
Set reg = CreateObject("Vbscript.RegExp")
If x = "S" Then
With reg
.Global = True
.Pattern = "\D+"
End With
Tr = reg.Replace(Rg, "")
ElseIf x = "H" Then
With reg
.Global = True
.Pattern = "[^\u4e00-\u9fa5]"
End With
Tr = reg.Replace(Rg, "")
ElseIf x = "Z" Then
With reg
.Global = True
.Pattern = "[^A-Za-z]"
End With
Tr = reg.Replace(Rg, "")
Else
Tr = ""
End If
End Function
具体操作:
1、打开excel
2、组合快捷键Alt+F11
3、右键当前,创建对应模块,粘贴代码
4、在单元格进行公式编辑,键入对应公式
=tr(A2,"S")
S是数字
H是汉字
Z是字母