|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim reg As New RegExp
- With reg
- .Global = True
- .Pattern = "([^\d]+)(\d+)"
- End With
- With Worksheets("sheet1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:a" & r)
- ReDim brr(1 To UBound(arr), 1 To 2)
- For i = 1 To UBound(arr)
- Set mh = reg.Execute(arr(i, 1))
- If mh.Count > 0 Then
- brr(i, 1) = mh(0).SubMatches(0)
- brr(i, 2) = Val(mh(0).SubMatches(1))
- End If
- Next
- .Range("c2").Resize(UBound(brr), UBound(brr, 2)).Value = brr
- .Range("c2").Resize(UBound(brr), UBound(brr, 2)).Sort key1:=.Range("c2"), order1:=xlAscending, key2:=.Range("d2"), order2:=xlAscending, Header:=lxno
- brr = .Range("c2").Resize(UBound(brr), UBound(brr, 2))
- .Range("c2").Resize(UBound(brr), UBound(brr, 2)).Clear
- For i = 1 To UBound(brr)
- arr(i, 1) = brr(i, 1) & brr(i, 2)
- Next
- .Range("b2").Resize(UBound(arr), 1) = arr
-
- End With
- End Sub
复制代码 |
|