View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Vasant Nanavati Vasant Nanavati is offline
external usenet poster
 
Posts: 1,080
Default Finding unique sets of numbers that total 200

Trying it again; will hopefully avoid the line wrap:

Sub AddThemUp()
Dim i As Integer, j As Integer, k As Integer, m As Integer
For i = 1 To 22
For j = i + 1 To 23
For k = j + 1 To 24
For m = k + 1 To 25
If Cells(i, 1) + Cells(j, 1) + Cells(k, 1) _
+ Cells(m, 1) = 200 Then
Union(Cells(i, 1), Cells(j, 1), Cells(k, 1), _
Cells(m, 1)).Select
Exit Sub
End If
Next
Next
Next
Next
End Sub

"Vasant Nanavati" <vasantn *AT* aol *DOT* com wrote in message
...
You could write a macro to do it:

Sub AddThemUp()
Dim i As Integer, j As Integer, k As Integer, m As Integer
For i = 1 To 22
For j = i + 1 To 23
For k = j + 1 To 24
For m = k + 1 To 25
If Cells(i, 1) + Cells(j, 1) + Cells(k, 1) + Cells(m,

1)
= 200 Then
Union(Cells(i, 1), Cells(j, 1), Cells(k, 1),
Cells(m, 1)).Select
Exit Sub
End If
Next
Next
Next
Next
End Sub

Assumes the numbers are in A1:A25.

--

Vasant

"Jeff" wrote in message
...
I have a list of 25 unique numbers, that are all less than
100. I am trying to figure out how many different sets of
those numbers equal a sum of 200. The set has to consist
of four number. For example, one set would be 5, 11, 89,
95. There are many more, but is there a way excel can use
a function or scenario to figure it out?
Thanks,
Jeff