RE: Combinations

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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
.



Relevant Pages

  • Re: Date of last update when sheet has changed
    ... Private Sub Worksheet_Change(ByVal Target As Range) ... like that because there is a regular offset of 3 colums in the colum areas ... Dim r1 As Range, r2 As Range, r41 As Range ...
    (microsoft.public.excel.programming)
  • Re: Date of last update when sheet has changed
    ... Private Sub Worksheet_Change(ByVal Target As Range) ... like that because there is a regular offset of 3 colums in the colum ... select View Code - this brings up a VBE window ...
    (microsoft.public.excel.programming)
  • Re: Date of last update when sheet has changed
    ... Private Sub Worksheet_Change(ByVal Target As Range) ... Because it is worksheet code, ... select View Code - this brings up a VBE window ...
    (microsoft.public.excel.programming)
  • Re: VBA- Verfahren hemmt Performance- gehts anders?
    ... > Private Sub Worksheet_Change(ByVal Target As Range) ... ob das für Deinen Suchtext einen Unterschied macht. ... > Ich könnte k in einer Zelle vermerken. ...
    (microsoft.public.de.excel)
  • Re: Check that only ASCII chars are used
    ... Private Sub Worksheet_Change(ByVal Target As Range) ... Dim Cel As Range ...
    (microsoft.public.excel.programming)