|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
这个用到了数组排序。
- Sub ykcbf() '//2024.4.22
- ReDim brr(1 To 100000, 1 To 1), ar(1 To 5)
- Set d = CreateObject("Scripting.Dictionary")
- Dim c As New Collection
- With Sheets("Sheet1")
- arr = .[a1:a5]
- sort2 arr, 1, 1
- For i = 1 To UBound(arr)
- ar(i) = CStr(arr(i, 1))
- Next
- For num1 = 1 To 5
- st1 = Mid(ar(1), num1, 1)
- For num2 = 1 To 5
- st2 = Mid(ar(2), num2, 1)
- For num3 = 1 To 5
- st3 = Mid(ar(3), num3, 1)
- For num4 = 1 To 5
- st4 = Mid(ar(4), num4, 1)
- For num5 = 1 To 5
- st5 = Mid(ar(5), num5, 1)
- If Len(Join(Split(st1 & st2 & st3 & st4 & st5, ""), "")) = 5 Then
- m = m + 1
- st = st & Chr(10) & st1 & st2 & st3 & st4 & st5
- s = Val(st1 & st2 & st3 & st4 & st5)
- If Not d.exists(s) Then
- c.Add s
- End If
- End If
- Next num5
- Next num4
- Next num3
- Next num2
- Next num1
- .[a7] = Mid(st, 2)
- ReDim br(1 To c.Count)
- For Each k In c
- n = n + 1
- br(n) = k
- Next
- sort1 br, True
- For i = 1 To UBound(br)
- br(i) = Format(br(i), "00000")
- Next
- tst = ""
- For i = 1 To UBound(br)
- tst = tst & Chr(10) & br(i)
- Next
- MsgBox "共有" & m & "种组合!"
- .[a8] = Mid(tst, 2)
- End With
- MsgBox "OK!"
- End Sub
复制代码
|
|