Results 1 to 8 of 8
  1. #1
    New Lounger
    Join Date
    Oct 2015
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts

    List the numbers that their sum is equal to the desired value

    Hello
    Users in cell BO1, enter the number you want by entering the numbers that their sum is equal to the desired number to the list
    I need the vba code to solve the problem
    attached file

  2. #2
    New Lounger
    Join Date
    Oct 2015
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Understand my question?

  3. #3
    Gold Lounger Maudibe's Avatar
    Join Date
    Aug 2010
    Location
    Pa, USA
    Posts
    2,639
    Thanks
    115
    Thanked 650 Times in 592 Posts
    general,

    Here is some code slightly modified form this site:

    http://www.tushar-mehta.com/excel/te...e_combinations

    Enter the Sum value in C3. In C2, enter the number of combinations you want returned; entering zero will return them all. Select from C2 down to include the numbers used in the combinations. All the combinations will be returned in column D.

    combinations1.png

    The code can be adapted to use the format matrix you supplied. The consensus is that this could best be achieved by Excel's Solver Tool.

    HTH,
    Maud
    Attached Files Attached Files
    Last edited by Maudibe; 2015-12-27 at 00:44.

  4. The Following User Says Thank You to Maudibe For This Useful Post:

    generalsamad (2015-12-27)

  5. #4
    New Lounger
    Join Date
    Oct 2015
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts

    List the numbers that their sum is equal to the desired value

    tanks Maud
    The answer is wrong to attach files
    Attached Files Attached Files

  6. #5
    Gold Lounger Maudibe's Avatar
    Join Date
    Aug 2010
    Location
    Pa, USA
    Posts
    2,639
    Thanks
    115
    Thanked 650 Times in 592 Posts
    Does your selection prior to running the code include cells C2 and C3?

  7. #6
    New Lounger
    Join Date
    Oct 2015
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Yes
    I run
    But the answer is wrong
    Untitled2.png

  8. #7
    Gold Lounger Maudibe's Avatar
    Join Date
    Aug 2010
    Location
    Pa, USA
    Posts
    2,639
    Thanks
    115
    Thanked 650 Times in 592 Posts
    general,

    It is actually the correct answer. The 2,5 combination is the second number (1100) and the 5th number (1400). The 3,4 combination is the 3rd and 4th numbers are 1200 and 1300, respectively.

    HTH,
    Maud

  9. The Following User Says Thank You to Maudibe For This Useful Post:

    generalsamad (2015-12-28)

  10. #8
    New Lounger
    Join Date
    Oct 2015
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Tanks Maud
    The question was solved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •