|
楼主 |
发表于 2019-6-30 11:15
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub 按钮8_Click()
- Range("L2:AB9999").ClearContents
- k0 = [j1].End(4).Row - 1
- If k0 <= 1 Then Exit Sub
- arr = [j2].Resize(k0, 1)
- k = 0
- ReDim brr(1 To 5040, 0 To 14)
- dic.RemoveAll
- For a = 0 To 6
- For b = a + 1 To 7
- For c = b + 1 To 8
- For d = c + 1 To 9
- s = a & b & c & d
- Call dgQPL("", s, 4)
- Next d, c, b, a
- [l2].Resize(dic.Count, 2) = Application.Transpose(Array(dic.Keys, dic.Items))
- [n2].Resize(5040, 15) = brr
- [L1].Resize(5041, 17).Sort key1:=Range("M1"), order1:=xlAscending, Header:=xlGuess
- MsgBox "建议:" & Format([l2], "0000")
- [l2].Select
- End Sub
- Sub dgQPL(x, y, j)
- Dim cr(0 To 14)
- If j = 1 Then
- k = k + 1
- For m = 1 To k0
- ts = compare(Format(arr(m, 1), "0000"), x & y)
- cr(ts) = cr(ts) + 1
- brr(k, ts) = brr(k, ts) + 1
- Next
- dic(x & y) = Application.Max(cr)
- Else
- For i = 1 To j
- Call dgQPL(x & Mid(y, i, 1), Left(y, i - 1) & Right(y, j - i), j - 1)
- Next
- End If
- End Sub
- Function compare(a, b)
- qa = 0: qb = 0
- For i = 1 To 4
- For j = 1 To 4
- If Mid(a, i, 1) = Mid(b, j, 1) Then
- If i = j Then qa = qa + 1 Else qb = qb + 1
- Exit For
- End If
- Next
- Next
- If qa = 0 Or qa = 3 Then
- compare = qa * 4 + qb
- ElseIf qa = 1 Or qa = 2 Then
- compare = qa * 4 + qb + 1
- ElseIf qa = 4 Then
- compare = 14
- End If
- End Function
复制代码
|
|