2024-11-03 14:29:54
我已经把所有的演示步骤录下来了,请查看下面动画:
宏最方便了。
打开excel,alt+F11,右侧你的文件VBAProject(***.xls),右击“插入--模块--双击模块,把下面代码粘贴进去,保存退出。重新打开excel,启用宏,就可以用了,具体A2=取值(取值(A1,"-zm"),"-sz")就可以得到了。
Function 取值(rng, types As String) As String
Dim obj As Object
Set obj = CreateObject("VBSCRIPT.REGEXP")
With obj
.Global = True
If types = "-hz" Then
.Pattern = "[一-﨩]"
ElseIf types = "-zm" Then
.Pattern = "[a-zA-Z]"
ElseIf types = "-sz" Then
.Pattern = "\d"
ElseIf types = "+hz" Then
.Pattern = "^[一-﨩]"
ElseIf types = "+zm" Then
.Pattern = "[^a-zA-Z]"
ElseIf types = "+sz" Then
.Pattern = "[^0-9]"
End If
取值 = .Replace(rng, "")
End With
End Function
'使用说明:
'去汉字:=取值(A2,"-hz")
'取汉字:=取值(A2,"+hz")
'去字母:=取值(A2,"-zm")
'取字母:=取值(A2,"+zm")
'去数字:=取值(A2,"-sz")
'取数字:=取值(A2,"+sz")
2024-11-03 13:40:33
2024-11-03 11:05:49
2024-11-03 05:42:32
2024-11-03 05:17:48