本文为《别怕,Excel VBA其实很简单(第3版)》随书问题参考答案

以下过程供参考:

Function MidS(ByVal txt, n As Byte) As String
Application.Volatile True
Dim T As String, i As Long
Dim NumStr As String, EnStr As String, Other As String
For i = 1 To Len(txt)
T = Mid(txt, i, 1)
If T Like "[0-9]" Then
NumStr = NumStr & T
ElseIf T Like "[A-z]" Then
EnStr = EnStr & T
Else
Other = Other & T
End If
Next i
If n = 0 Then
MidS = NumStr
ElseIf n = 1 Then
MidS = EnStr
ElseIf n = 2 Then
MidS = Other
Else
MidS = "#参数错误!"
End If
End Function

声明:本站所有文章均出自互联网,只为学习之用;如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。