Excel提取指定字符(汉字,字母,数字)

=myget(字符串,1)   '取出中文字符

=myget(字符串,2)   '取出英文字母

=myget(字符串,0)       '取出数字

取出数字第2个参数可以省略,=myget(字符串)

Function MyGet(Srg As String, Optional n As Integer = False) Dim i As Integer Dim s, MyString As String Dim Bol As Boolean For i = 1 To Len(Srg) s = Mid(Srg, i, 1) If n = 1 Then Bol = Asc(s) < 0 ElseIf n = 2 Then Bol = s Like "[a-z,A-Z]" ElseIf n = 0 Then Bol = s Like "#" End If If Bol Then MyString = MyString & s Next MyGet = IIf(n = 1 Or n = 2, MyString, Val(MyString)) End Function

你可能感兴趣的:(VBA)