ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Finding unique sets of numbers that total 200 (https://www.excelbanter.com/excel-programming/295832-finding-unique-sets-numbers-total-200-a.html)

jeff

Finding unique sets of numbers that total 200
 
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

Vasant Nanavati

Finding unique sets of numbers that total 200
 
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




Vasant Nanavati

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







All times are GMT +1. The time now is 02:58 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com