- Dim sj As Variant, jg() As Variant, k%, sz!, m%
- Sub test()
- Dim r%, i%
- Dim arr, brr
- With Worksheets("sheet1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:b" & r)
- sz = Abs(.Range("e3"))
- ReDim sj(1 To Application.Sum(Application.Index(arr, 0, 1)), 1 To 3)
- m = 0
- For i = 1 To UBound(arr)
- For j = 1 To arr(i, 1)
- If j * arr(i, 2) <= Abs(sz) Then
- m = m + 1
- sj(m, 1) = -1 * j
- sj(m, 2) = arr(i, 2)
- sj(m, 3) = j * arr(i, 2)
- Else
- Exit For
- End If
- Next
- Next
- k = 0
- ReDim jg(1 To 10000, 1 To 1)
- dg "", 1, 0, 1
- .Columns(7).ClearContents
- If k > 0 Then
- .Range("g1").Resize(k, UBound(jg, 2)) = jg
- End If
- End With
- End Sub
- Sub dg(ss$, n%, he!, j%)
- If he + sj(j, 3) = sz Then
- k = k + 1
- jg(k, 1) = ss & "(" & sj(j, 1) & "*" & sj(j, 2) & ")=" & -1 * sz
- End If
- If j < m And n <= 2 Then
- If he + sj(j, 3) < sz Then
- dg ss & "(" & sj(j, 1) & "*" & sj(j, 2) & ")+", n + 1, he + sj(j, 3), j + 1
- End If
- dg ss, n, he, j + 1
- End If
- End Sub
复制代码 |