It depends how many of the 100 integers you're allowed to use in the sum, ie
if you set the limit at 5 you would rule out 1+2+3+4+5+55 because it
contained 6 components.
If you don't limit yourself to a low number it'll take far far too long to
try all combinations.
The code below works for at most 3 combinations - you can extend this to
more using the obvious pattern. It goes to 101 rows on purpose otherwise
you're accidentally specifying exactly 3 components, not up to 3.
Sub demo()
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim z As Integer
With Range("a1")
For a = 0 To 101
For b = a + 1 To 101
For c = b + 1 To 101
If .Offset(a, 0).Value + .Offset(b, 0).Value + .Offset(c,
0).Value = 70 Then
.Offset(z, 1).Value = .Offset(a, 0).Value & " / " &
..Offset(b, 0).Value & " / " & .Offset(c, 0).Value
z = z + 1
End If
Next c
Next b
Next a
End With
End Sub
"jay dean" wrote:
Hi,
Each cell in Range("A1:A100") contains an integer. I would like a macro
or function that will generate a list of all possible numbers in the
range that SUM up to 70 and place them in column C. The delimiter I'd
like to use for each solution is "\".
For example, column C could contain:
C1: 20 \ 50
C2: 60 \ 10
C3: 15 \ 35 \ 20
c4: 17 \ 33 \ 16 \4
.. and so on..
Any help would be appreciated.
Thanks
Jay
*** Sent via Developersdex http://www.developersdex.com ***