There's probably a much more efficient way to do this, but hey - it works!
The code is based on a worksheet being in this exact format.
A B C D E F
1
2 LIST TARGET: NUMBER1 NUMBER2
3 1234 8966
4 63
5 8903
6 3446
7 8112
8 854
Option Explicit
Public Sub FindSolutions()
Dim num1 As Currency
Dim num2 As Currency
Dim aRow As Long
Dim bRow As Long
Const icol As Integer = 1
Dim curTarget As Currency
Const resultCol As Integer = 5
Dim cRow As Long
Dim blnSkip As Boolean
ActiveSheet.Range("E3:F500").ClearContents 'clear existing #s in columns
E-F
curTarget = ActiveSheet.Range("C3") 'target value
aRow = 3 'start at top
Do Until Cells(aRow, icol) = "" 'loop thru list of values in column A
bRow = 3
Do Until Cells(bRow, icol) = "" 'go thru values below cell we're on
right now
num1 = Cells(aRow, icol) 'grab # in current cell
num2 = Cells(bRow, icol) 'grab # in next cell down
If num1 + num2 = curTarget Then 'sum of 2 #s = target value
'CHECK IF THEY'RE ALREADY IN THE LIST OF SOLUTIONS
cRow = 3
blnSkip = False
Do Until Cells(cRow, resultCol) = ""
If Cells(cRow, resultCol) = num2 Then
If Cells(cRow, resultCol + 1) = num1 Then
blnSkip = True '#s are already in solution columns
End If
End If
cRow = cRow + 1
Loop
If blnSkip = False Then 'add these #s to solution lists
Cells(cRow, resultCol) = num1
Cells(cRow, resultCol + 1) = num2
End If
End If
bRow = bRow + 1
Loop
aRow = aRow + 1
Loop
End Sub
Hope this helps!
Mike
" wrote:
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.