Thread: Combination Sum
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Bernie Deitrick Bernie Deitrick is offline
external usenet poster
 
Posts: 5,441
Default Combination Sum

Harald,

That works fine if only pairs are added, but how about 3, 4, 5, 6.....699 numbers being added?

Too many.

If it were just pairs, you could use worksheet functions to show the matches:

=IF(NOT(ISERROR(MATCH(8966-A2,$A$2:$A$701,FALSE))),A2 & " & " & 8966-A2,"")

Bernie
MS Excel MVP


"Harald Staff" wrote in message ...
Hi

This tests for one or two combinations. Put more loops inside the y loop (like For z = y+1 to 700)
for mo

Sub test()
Dim x As Long
Dim y As Long
Dim D1 As Double, D2 As Double
For x = 1 To 699
Application.StatusBar = x
D1 = Cells(x, 1).Value
If D1 = 8966 Then
MsgBox D1, , "Found one"
End If
For y = x + 1 To 700
D2 = Cells(y, 1).Value
If D1 + D2 = 8966 Then
MsgBox D1 & " " & D2, , "Found one"
End If
Next
Next
End Sub

HTH. Best wishes Harald

skrev i melding
...
Hi

I need help in solving for an issue in excel. A macro is required.

We have a list of 700 numbers and we need to find out how many
combinations match a particular number, if we add numbers from the
list of 700. Example:

List of numbers:
1234
63
8903
3446
8112
854
... and so on

Target: 8966

Solution:
Option 1:
8112+854
Option 2:
63+8903

Is this possible in excel macro. I found one here, but this is not
useful for more than 4 numbers.

http://en.allexperts.com/q/Excel-105...s-x-number.htm

I would appreciate it if a solution to this is available on excel or
any other software.