Thread: Combinations
View Single Post
  #16   Report Post  
Posted to microsoft.public.excel.programming
BOSS BOSS is offline
external usenet poster
 
Posts: 123
Default Combinations

This is excellent...
Sam you rock... thansk a lot for your help...

Boss

"Sam Wilson" wrote:

Ok, change

For b = 0 To x
For c = 0 To x
For d = 0 To x
For e = 0 To x
For f = 0 To x

To

For b = 4 To x
For c = 3 To b-1
For d = 2 To c-1
For e = 1 To d-1
For f = 0 To e-1

and insert a 0 at the top of row B (you need a zero to represent unused
numbers in a combination)

"Boss" wrote:

Thanks a lot for your help...

But i cannot repeat number... In other words one number cannot be used again
for one comparison.

Hope you solve this issue the way you did other...

Thx!
Boss

"Sam Wilson" wrote:


After your further explanation, I've written this with column B and A
reversed. It's going to add up combinations from A to try to find targets in
B. Change A1 to B1 and B1 to A1 to make it work.

"Sam Wilson" wrote:

This will work but won't be fast. It writes the first solution it finds to
column c next to the target number, and assumes you have no column headers:

Sub demo()

Dim a As Integer, b As Integer, c As Integer, d As Integer, e As Integer, f
As Integer, x As Integer

Do While Not IsEmpty(Range("B1").Offset(a, 0))
x = Range("a1").End(xlDown).Row
For b = 0 To x
For c = 0 To x
For d = 0 To x
For e = 0 To x
For f = 0 To x
If Range("a1").Offset(b, 0) + Range("a1").Offset(c,
0) + Range("a1").Offset(d, 0) + Range("a1").Offset(e, 0) +
Range("a1").Offset(f, 0) = Range("B1").Offset(a, 0) Then
Range("C1").Offset(a, 0).Value =
Range("a1").Offset(b, 0).Address(False, False) & ", " & Range("a1").Offset(c,
0).Address(False, False) & ", " & Range("a1").Offset(d, 0).Address(False,
False) & ", " & Range("a1").Offset(e, 0).Address(False, False) & ", " &
Range("a1").Offset(f, 0).Address(False, False)
GoTo EndLoop
End If
Next f
Next e
Next d
Next c
Next b

EndLoop:
a = a + 1
Loop

End Sub


"Boss" wrote:

Thanks for the reply...

Actually i need to add five or less numbers which are in column A to any
number in column B.

Column A has 200 numbers And column B has about 50 numbers


Col A Col B
256 490
234
325
214
256
147

In the example 256+234 = 490

Please help.
thanks!
Boss


"Mike H" wrote:

Hi,

This isn't clear, you want all possible conbinations of 200 numbers but how
may do you want in each number set? what do you want them to add up to?

Mike

"Boss" wrote:

Hi,

I have about 200 numbers in a column. I need to find all the possible
additions which are possible using those numbers. My final aim is to match
the answers with some other data.

I did a lot of search in google but failed. please help.

Thanks!
Boss