|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
参与一下,来一个暴力拆解,全列出来,然后找出最接近的,数据太多就不行了。
- Option Explicit
- Dim Arr, Nrr()
- Dim Q As Long, L As Long, M As Double
- Sub Main()
- Dim Brr, i&, xStr As String
- Brr = Range("b2:b15")
- M = [c18]
- L = UBound(Brr)
- ReDim Arr(1 To L + 1)
- For i = 1 To L
- Arr(i) = Brr(i, 1)
- Next
-
- Q = 0
- For i = 1 To L
- MergeSub 1, 1, i, "", 0
- Next i
-
- For i = 1 To Q
- If Nrr(2, i) < M Then M = Nrr(2, i): xStr = Nrr(1, i)
- Next i
- Brr = Split(xStr, ",")
- [c2:c15].Clear
- For i = 0 To UBound(Brr) - 1
- Cells(Val(Brr(i)) + 1, "c") = Cells(Val(Brr(i)) + 1, "b")
- Next i
-
- End Sub
- Sub MergeSub(ByVal x As Long, ByVal y As Long, ByVal C As Long, ByVal S As String, ByVal N As Double)
-
- If x > L + 1 Or N > M Then Exit Sub
-
- If y > C Then
- Q = Q + 1
- ReDim Preserve Nrr(1 To 2, 1 To Q)
- Nrr(1, Q) = S
- Nrr(2, Q) = M - N
- Exit Sub
- End If
-
- MergeSub x + 1, y + 1, C, S & x & ",", N + Arr(x)
- MergeSub x + 1, y, C, S, N
-
- End Sub
复制代码 |
|