[FONT=Fixedsys]Option Explicit[/FONT]
[FONT=Fixedsys][/FONT]
[FONT=Fixedsys]Sub CombineAndCheckTotal()[/FONT]
[FONT=Fixedsys][/FONT]
[FONT=Fixedsys] Const vTargetValue As Variant = 16455.56
Dim ws As Worksheet
Dim vArray As Variant
Dim sMask As String
Dim iLastRow As Long
Dim iRow As Long
Dim vTotal As Variant
Dim iInd As Long
Dim sMessage As String
Dim iOutRow As Long
Dim dStart As Date
Application.Cursor = xlWait
dStart = Now()
Set ws = ThisWorkbook.Sheets(1)
iLastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
vArray = Application.Transpose(ws.Range("A2:A" & iLastRow))
sMask = String(UBound(vArray), "0")
iOutRow = 1
Do Until sMask = String(UBound(vArray), "1")
Increment sMask
vTotal = 0
For iInd = 1 To UBound(vArray)
If Mid(sMask, iInd, 1) = "1" Then vTotal = vTotal + vArray(iInd)
Next iInd
vTotal = Round(vTotal, 2)
If vTotal = vTargetValue Then
sMessage = ""
For iInd = 1 To UBound(vArray)
If Mid(sMask, iInd, 1) = "1" Then sMessage = sMessage & ", " & vArray(iInd)
Next iInd
[COLOR=green] ' option #1 - display combination on worksheet
[/COLOR][COLOR=blue] If iOutRow = 1 Then ws.Columns("B").ClearContents
iOutRow = iOutRow + 1
ws.Cells(iOutRow, "B") = Mid(sMessage, 2)
[/COLOR][COLOR=green] ' option #2 - display combination in message box
[/COLOR][COLOR=red] MsgBox "Combination found:-" & Space(10) & vbCrLf & Replace(sMessage, ",", vbCrLf & Space(5)), _
vbOKOnly + vbInformation
[/COLOR] End If
DoEvents
Loop
Application.Cursor = xlDefault
MsgBox "Finished:-" & vbCrLf & vbCrLf _
& Space(5) & CStr(iLastRow - 1) & " numbers in list" _
& Space(10) & vbCrLf & vbCrLf _
& Space(5) & Format(2 ^ (iLastRow - 1) - 1, "#,###") & " combinations checked" _
& Space(10) & vbCrLf & vbCrLf _
& Space(5) & "Run time: " & Format(Now() - dStart, "hh:nn:ss") & Space(10), _
vbOKOnly + vbInformation
End Sub[/FONT]
[FONT=Fixedsys][/FONT]
[FONT=Fixedsys]Function Increment(ByRef aMask As String)[/FONT]
[FONT=Fixedsys][/FONT]
[FONT=Fixedsys] Dim iPtr As Integer
For iPtr = 1 To Len(aMask)
If Mid(aMask, iPtr, 1) = "0" Then
Mid(aMask, iPtr, 1) = "1"
Exit Function
Else
Mid(aMask, iPtr, 1) = "0"
End If
Next iPtr[/FONT]
[FONT=Fixedsys][/FONT]
[FONT=Fixedsys]End Function
[/FONT]