|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Option Explicit
Sub test()
Dim ar, br, cr$(), dr, r&, i&, j&
ReDim ar(1 To 999)
For i = 1 To UBound(ar)
ar(i) = Format(i, "000")
Next i
br = [A2].CurrentRegion
With CreateObject("Vbscript.RegExp")
For i = 1 To UBound(br)
cr = Split(Trim(br(i, 1)))
For j = 0 To UBound(cr)
cr(j) = Mid(cr(j), 1, 1) & "\d?" & Mid(cr(j), 2, 1)
Next j
.Pattern = Join(cr, "|")
Erase cr: r = 0
For j = 1 To UBound(ar)
If .test(numSort(CStr(ar(j)))) Then
r = r + 1
ReDim Preserve cr(1 To r)
cr(r) = ar(j)
End If
Next j
br(i, 1) = Join(cr)
Next i
End With
Columns(3).ClearContents
[C2].Resize(UBound(br)) = br
Beep
End Sub
Function numSort(strTxt$) As String
Dim ar(9) As Byte, i&, n As Byte
For i = 1 To Len(strTxt)
n = Val(Mid(strTxt, i, 1))
ar(n) = ar(n) + 1
Next
For i = 0 To 9
If ar(i) > 0 Then numSort = numSort & String(ar(i), CStr(i))
Next
End Function
|
|