# Need help for a mathematical problem

#### andrescane

##### New Member
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

Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

#### TryingToLearn

##### Well-known Member
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

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) + 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 ?

#### andrescane

##### New Member
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

#### SIXTH SENSE

##### Well-known Member
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>

#### andrescane

##### New Member
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

#### CraigM

##### Active Member
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.

##### MrExcel MVP
"Also I believe the solver method will only give you the first solution that it "discovers". "

Correct.

#### Yogi Anand

##### MrExcel MVP
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
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.

Replies
2
Views
76
Replies
3
Views
120
Replies
1
Views
245
Replies
5
Views
124
Replies
3
Views
383

1,187,178
Messages
5,962,051
Members
438,578
Latest member
MrJimC

### 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.

### Which adblocker are you using?

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

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