Sub test()
Dim arr, Reg As Object, brr, mat As Object
arr = Range("A1").CurrentRegion.Value
Set Reg = CreateObject("vbscript.regexp")
With Reg
.Pattern = "([a-zA-Z]+)(\d+)"
.Global = True
For i = 2 To UBound(arr)
Set mat = .Execute(arr(i, 1))
j = 0
For Each M In mat
If j <> mat.Count - 1 Then '位置判断
Key = mat(j).submatches(1) * 1 <> mat(j + 1).submatches(1) - 1
Else
Key = mat(j - 1).submatches(1) * 1 <> mat(j).submatches(1) - 1
End If
If j = 0 Then '第一个数据处理
If Key Then k = 0 Else k = 1
arr(i, 2) = mat(j)
ElseIf j <> mat.Count - 1 Then '中间数据处理
If k = 1 Then
If Key Then
arr(i, 2) = arr(i, 2) & "~" & mat(j)
k = 0
End If
Else
arr(i, 2) = arr(i, 2) & "," & mat(j)
k = 1
End If
Else '最后一个数据处理
If Key Then arr(i, 2) = arr(i, 2) & "," & mat(j) Else arr(i, 2) = arr(i, 2) & "~" & mat(j)
End If
j = j + 1
Next
Next i
End With
Range("A1").CurrentRegion.Value = arr
End Sub
好了,本期教程就到这里啦,走过路过的点个关注分享一下吧,谢谢啦