How about these versions - requires that one number be used twice...though i think it is impossible to get 8 from the sum of 3 unique and 1 doubled number (1 + 1 + 2 + 3 + 4 = 11 would be the lowest possible sum) is the requirement for 5 numbers (the first version) or just for 4 numbers - 2 unique and one doubled (the second version)?
Sub TestMacro5numbers()
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim l As Integer
Dim c As Integer
Dim iTar As Integer
iTar = 8 'Value you need to sum to....
c = Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To c - 3
For j = i + 1 To c - 2
For k = j + 1 To c - 1
For l = k + 1 To c
If 2 * Cells(i, 1) + Cells(j, 1) + Cells(k, 1) + Cells(l, 1) = iTar Then
MsgBox i & " + " & i & " + " & j & " + " & k & " + " & l
End If
If Cells(i, 1) + 2 * Cells(j, 1) + Cells(k, 1) + Cells(l, 1) = iTar Then
MsgBox i & " + " & j & " + " & j & " + " & k & " + " & l
End If
If Cells(i, 1) + Cells(j, 1) + 2 * Cells(k, 1) + Cells(l, 1) = iTar Then
MsgBox i & " + " & j & " + " & k & " + " & k & " + " & l
End If
If Cells(i, 1) + Cells(j, 1) + Cells(k, 1) + 2 * Cells(l, 1) = iTar Then
MsgBox i & " + " & j & " + " & k & " + " & l & " + " & l
End If
Next l
Next k
Next j
Next i
End Sub
Sub TestMacro4Numbers()
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim c As Integer
Dim iTar As Integer
iTar = 8 'Value you need to sum to....
c = Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To c - 2
For j = i + 1 To c - 1
For k = j + 1 To c
If 2 * Cells(i, 1) + Cells(j, 1) + Cells(k, 1) = iTar Then
MsgBox i & " + " & i & " + " & j & " + " & k
End If
If Cells(i, 1) + 2 * Cells(j, 1) + Cells(k, 1) = iTar Then
MsgBox i & " + " & j & " + " & j & " + " & k
End If
If Cells(i, 1) + Cells(j, 1) + 2 * Cells(k, 1) = iTar Then
MsgBox i & " + " & j & " + " & k & " + " & k
End If
Next k
Next j
Next i
End Sub
Bookmarks