正则表达式
If Selection.Cells.Count = 0 Then Exit Sub
'秋色烽火原创代码,转载请保留信息。 2018-05-23
Dim rng As Range
Dim reg, mh, mhk
Set rng = Selection.Cells
Set reg = CreateObject("vbscript.regexp")
reg.Pattern = "([^\d]+)(\d+)([^\d]+)"
reg.Global = True
For I = 1 To rng.Cells.Count
Set mh = reg.Execute(rng.Cells(I, 1))
If mh.Count <> 0 Then
For Each mhk In mh
Debug.Print mhk.SubMatches.Item(0) & vbCrLf & mhk.SubMatches.Item(1) & vbCrLf & mhk.SubMatches.Item(2)
Next
End If
Next
设有汉字 数字 汉字的单元格在A2,,请输入公式:
B2:=LEFT(LEFT(A2,10),LENB(LEFT(A2,10))-LEN(LEFT(A2,10)))
C2:=MID(A2,LENB(LEFT(A2,10))-LEN(LEFT(A2,10))+1,LEN(A2)-LEN(B2)-LEN(D2))
D2:=RIGHT(RIGHT(A2,10),LENB(RIGHT(A2,10))-LEN(RIGHT(A2,10)))
下拉填充。
见截图
B2输入 =LEFTB(A2,SEARCHB("?",A2)-1)
C2输入 =LEFT(SUBSTITUTE(A2,B2,),2*LEN(SUBSTITUTE(A2,B2,))-LENB(SUBSTITUTE(A2,B2,)))
D2输入 =SUBSTITUTE(A2,B2&C2,)
公式下拉