- Dim mycount As Long, s(1 To 65536, 1 To 1), num As Long
- Sub main()
- Dim a, b
- num = 45
- b = Array(10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
- ReDim a(num)
- a(0) = b(0)
- search num, 0, 0, a, b
- [a1].Resize(65536) = s
- MsgBox "OK", , "Total count=" & mycount
- End Sub
- Sub search(ByVal n As Long, ByVal j As Long, ByVal index As Long, ByRef a, ByRef b)
- For i = index To UBound(b)
- If n = b(i) Then
- mycount = mycount + 1
- a(j) = b(i)
- For k = 0 To j
- s(mycount, 1) = s(mycount, 1) & " " & a(k)
- Next
- s(mycount, 1) = Replace(Trim(s(mycount, 1)), " ", "+") & "=" & num
- Else
- a(j) = b(i)
- If n >= b(i) Then search n - b(i), j + 1, i, a, b
- End If
- Next
- End Sub