Need help for a mathematical problem

andrescane

New Member
Joined
Jan 20, 2004
Messages
3
First of all, sorry for my english. This is the problem: given some number and a group of other numbers, i need to calculate which of these number are the result of an addition that have as a result the first number. For example: result 100, group of numbers 20, 80, 3, 5. The correct answer is: 20 and 80.
do anybody know if this problem can be resolved in excel??? Thanks.
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Very dirty but seems to work:

Result goes in A1

list of numbers in A3 to A??

results are in message box and written to column c

Code:
Sub addit()
    Dim result, x, y As Integer
    Dim count, r, c

    r = "$C$1:" & Range("c65536").End(xlUp).Address
    Range(r).ClearContents
    With Sheets("sheet1")
        result = Cells(1, 1)
        count = Range("a3:a65536").End(xlDown).Offset(-2, 0).Row
        For x = 2 To count
            For y = 2 To count
                If Cells(x, 1).Address <> Cells(y, 1).Address Then
                    If Cells(x, 1) + Cells(y, 1) = result Then
                        MsgBox (" A1   =      A" & x & "  +   A" & y _
                              & Application.Rept(vbLf, 1) & result & "   =    " & Cells(x, 1).Value & "   +   " & Cells(y, 1).Value)
                        r = "A" & x & "  +   A" & y
                        Range("c3:c65536").End(xlUp).Offset(1, 0) = r

                    Else
                    End If
                End If
            Next y
        Next x
    End With
End Sub



Anyone care to clean it up ?
 
Upvote 0
Thanks, but it seems to be a problem. It appears an error (I am translate from spanish) "It has produced error '9' in execution time. Subindex out of interval" .
I think that the line is:
With Sheets("sheet1")
Can you fix it? I really thank you anyway
 
Upvote 0
hi!
set up.
column A-numbers to search
D1 result

then try this one.

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> Combinationx()
res = Range("d1").Value
<SPAN style="color:#00007F">For</SPAN> i = 2 <SPAN style="color:#00007F">To</SPAN> Range("a65536").End(xlUp).Row
    <SPAN style="color:#00007F">For</SPAN> j = 2 <SPAN style="color:#00007F">To</SPAN> Range("a65536").End(xlUp).Row
        <SPAN style="color:#00007F">If</SPAN> Range("a" & i).Value + Range("a" & j).Value = res <SPAN style="color:#00007F">Then</SPAN>
            Range("d" & Range("D65536").End(xlUp).Row + 1).Value = Range("a" & i).Value & "+" & Range("a" & j).Value & "=" & res
        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
    <SPAN style="color:#00007F">Next</SPAN> j
<SPAN style="color:#00007F">Next</SPAN> i
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0
The macro that Sixth Sense left works, but only with two numbers. I need that it works with many more. For example: the result is 100 and the numbers are 10, 20, 60, 35, 56, 10. The correct numbers are 10+20+60+10
Can anybody give me the solution?
Thanks
 
Upvote 0
My addin will do that for you. Also I believe the solver method will only give you the first solution that it "discovers". In reality there may be more than one solution. Again, the addin will give you all possible solutions.
 
Upvote 0
"Also I believe the solver method will only give you the first solution that it "discovers". "

Correct.
 
Upvote 0
Hi andrescane:

Welcome to MrExcel Board!

I was just having a little play with what you are trying to accomplish -- as presented in the following illustration ...
y040120h1a.xls
ABCDEFGHIJK
1Numberssumofanycombinationofnumbers=100
220successfulmatches
380sumofanysumofanysumofall
43twonumbersthreenumbersfournumbers
55000
6110000
700000
800
9
102080       
11     
12  
Sheet2


This formula based approach may not be of any practical use to you -- but you may find it to be of some interest.
 
Upvote 0

Forum statistics

Threads
1,213,526
Messages
6,114,122
Members
448,550
Latest member
CAT RG

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top