Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Erika
 
Posts: n/a
Default Total a Combination of Numbers

I have a list of 19 numbers, what I need to know is what combination of these
add up to 690. I'm drawing a blank on how I could set this up in Excel.
  #2   Report Post  
Stevie_mac
 
Posts: n/a
Default

This is probably best done in a macro

To make this example work...

* Put your 19 Values in G1 to G19
* Open VB & add & run the following macro

Option Explicit
Public Sub WhichNosAddTo690()
Dim i As Variant
Dim CurrentCell As Range
Dim StartCell As Range
Dim OutputCell As Range
Dim iTest As Long, sOut As String
Dim bitno As Integer
'Set starting cells for input & output
Set StartCell = Range("G1")
Set OutputCell = Range("H1")


For i = 0 To (2 ^ 19)
iTest = 0
For bitno = 0 To 18 '19 bits
If ((i And (2 ^ bitno)) 0) Then
iTest = iTest + StartCell.Offset(bitno).value
End If
Next
If iTest = 690 Then
sOut = ""
For bitno = 0 To 18 '19 bits
If ((i And (2 ^ bitno)) 0) Then
sOut = sOut & " " & StartCell.Offset(bitno).value
End If
Next
OutputCell.value = Trim(sOut)
Set OutputCell = OutputCell.Offset(1, 0)
End If
Next

End Sub

WHAT IT DOES:
* Add all possible combinations of values in cells G1 to G19.
* Outputs a space separated list of all the combinations that add up to 690 in Col H

IMPORTANT NOTE:
* It will take a while for this function to complete, be patient.

HOW IT WORKS...
'Loop all possible values upto 2^19
'Use the bit pattern of loop 'i' to
'test all the possible combinations
'e.g. when i = 9, a 19 bit - bit pattern would look like
' 0000000000000001001
'Based on this bit pattern, test the sum of
'G1+G4
'when i = 22, the 19 bit - bit pattern would look like
' 0000000000000010110
'Based on this bit pattern, test the sum of
'G2+G3+G5
'etc etc

"Erika" wrote in message ...
I have a list of 19 numbers, what I need to know is what combination of these
add up to 690. I'm drawing a blank on how I could set this up in Excel.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Count and Sum Total occurrances of two specific numbers Sam via OfficeKB.com Excel Worksheet Functions 10 March 29th 05 08:13 PM
How do I add a range of numbers to sum a specific total? SJoshi Excel Worksheet Functions 3 February 15th 05 01:16 PM
Total remaining formula jbsand1001 Excel Worksheet Functions 2 January 6th 05 04:17 PM
To find a combination of numbers that equal a set amount? Larry Morris Excel Discussion (Misc queries) 6 December 17th 04 05:39 PM
how do I add a list of numbers to get a total bibs Excel Discussion (Misc queries) 2 November 27th 04 03:31 AM


All times are GMT +1. The time now is 05:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"