使用VBA自定义函数和下面公式:
在B1输入:
="4305242664"&text(takeout(A1,2,1),"00")
公式下拉
函数:TAKEOUT(自己以前用的,针对你的情况可以自己简化一下)
语法:TAKEOUT(被取字符串,取值类型,序号)
被取字符串:含有数字、汉字和字母的不规则字符串。
取值类型:(数字1、2)1代表汉字子串,2代表数字子串。
序号:(数字1到3)代表要取出子串在被取字符串从左到右的第几个。
Function takeout(str, zt, s)
On Error GoTo errtakeout1
Dim m As Integer
str = str & " "
If s = 1 Then
m = 0
Else
If s = 2 Then
m = -2
Else
If s = 3 Then
m = -4
Else
GoTo errtakeout1
End If
End If
End If
If zt = 1 Then
For i = 1 To Len(str)
If Asc(Mid(str, i, 1)) >= -20319 And Asc(Mid(str, i, 1)) <= -2050 Then
If m = -4 Then m = -3
If m = -2 Then m = -1
If m = 0 Then m = i
Else
If m = -3 Then m = -2
If m = -1 Then m = 0
If m > 0 Then
takeout = Mid(str, m, i - m)
Exit Function
End If
End If
Next
takeout = ""
Exit Function
Else
If zt = 2 Then
For i = 1 To Len(str)
If Asc(Mid(str, i)) > 47 And Asc(Mid(str, i)) < 58 Then
If m = -4 Then m = -3
If m = -2 Then m = -1
If m = 0 Then m = i
Else
If m = -3 Then m = -2
If m = -1 Then m = 0
If m > 0 Then
takeout = Mid(str, m, i - m)
Exit Function
End If
End If
Next
takeout = ""
Exit Function
Else
GoTo errtakeout1
End If
End If
errtakeout1:
takeout = "#NAME?"
End Function