excel按条件拆分文本字符串函数

Public Function part(TextStringA As Variant, TextStringB As Variant, Optional Space As Variant = “;”) As Double
‘定义TextStringA为待拆分字符串,TextStringB为拆分字段依据,Space为连接各个字段之间的符号(可选,默认为”;”)
Dim i%, LenStr%, PartStr$
LenStr = Len(TextStringB)
For i = 0 To UBound(Split(TextStringA, Space), 1)
PartStr = Split(TextStringA, Space)(i)
If TextStringB = Left(PartStr, LenStr) Then
part = Replace(PartStr, TextStringB, “”)
Exit Function
End If
Next i
End Function

 » 本站地址:http://www.gomoth.com

标签: