+ Reply to Thread
Results 1 to 14 of 14

How To Find Maximum Sum From The List With nth Number of Values Not Greater Than To X

  1. #1
    Registered User
    Join Date
    12-25-2021
    Location
    Riyadh
    MS-Off Ver
    365
    Posts
    6

    Post How To Find Maximum Sum From The List With nth Number of Values Not Greater Than To X

    Cross-posted at https://www.mrexcel.com/board/thread...-cell.1191127/ with solution


    Hi, I am new here.
    I have a list of different numbers in range A1:A18
    What i need is to sum up any 3 or 4 values that can be near to 240 but not more than that
    For Example, I have This List

    Range A1 to A18 (Largest to Smallest)
    A1: 87
    A2: 86
    A3: 85
    A4: 84
    A5: 83
    A6: 82
    A7: 81
    A8: 81
    A9: 72
    A10: 70
    A11: 69
    A12: 66
    A13: 63
    A14: 59
    A15: 57
    A16: 54
    A17: 53
    A18: 50


    Now i need Any Combination of 3 values or 4 values which sums the maximum number but the total always be less than 240.
    Like in Above List The Possible Combinations to make Totals which should be less than 240 is below.

    85 + 84 + 70 = 239
    83 + 82 + 72 = 237
    81 + 81 + 69 = 231
    63 + 59 + 57 + 54 = 233
    53 + 50 = 103

    It should give me the totals Like That but not more than 240
    and the cells which are used should not be used again like in the first combination Cell A3 (i.e. 85) , A4 (84), and A10 (70) is used so it should not be used again.


    if there is any macro any brother can help for this.

    Thanks for your support in advance.
    Last edited by 6StringJazzer; 12-25-2021 at 09:21 AM.

  2. #2
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: How To Find Maximum Sum From The List With nth Number of Values Not Greater Than To X

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: How To Find Maximum Sum From The List With nth Number of Values Not Greater Than To X

    Please read the rules before continuing.

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however it has been brought to our attention that the same query has been posted on one or more other forums and you have not provided the required cross-post link(s) here.

    Please see Forum Rule #3 about cross-posting and adjust accordingly. Read this to understand why we (and other sites like us) consider this to be important.

    I have provided the link this time, but there is already a solution there that you said works. That is why we have this rule.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Registered User
    Join Date
    12-25-2021
    Location
    Riyadh
    MS-Off Ver
    365
    Posts
    6

    Post Re: How To Find Maximum Sum From The List With nth Number of Values Not Greater Than To X

    Thanks bsalv

    What I need is solved here in this macro

    Please Login or Register  to view this content.
    Now its done but its giving me only 3 values pair.


    But I want to be like this,
    85 + 84 + 70 = 239
    83 + 82 + 72 = 237
    81 + 81 + 69 = 231
    63 + 59 + 57 + 54 = 233
    53 + 50 = 103

    So the macro should see whether 2, 3, 4, or more values can sumup to create a total which is less than 240 so it should also write it.

    hope you get my point and will help me to fix that

    Thanks in advance for your kind support.

    I have also posted this question on mrexcel forum. i am not allowed to link to that site, how i can.
    Attached Images Attached Images

  5. #5
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: How To Find Maximum Sum From The List With nth Number of Values Not Greater Than To X

    working in your workbook is slow, working in memory is rocket speed.
    So collectiong data and only once writing to the workbook
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by bsalv; 12-25-2021 at 10:50 AM.

  6. #6
    Registered User
    Join Date
    12-25-2021
    Location
    Riyadh
    MS-Off Ver
    365
    Posts
    6

    Re: How To Find Maximum Sum From The List With nth Number of Values Not Greater Than To X

    thanks bsalv but it is counting and searching for combinations continuously. i need to count each cell one time only in one combination. like A1 cell is used so it should not be used again,
    so by this technique the result will be pasted in 4 or 5 rows. i need exactly as below in image.
    Attached Images Attached Images

  7. #7
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: How To Find Maximum Sum From The List With nth Number of Values Not Greater Than To X

    Understood. What is the goal ?

    If you get there 10 possible solutions, which one is the best ?
    Now you have 5 times <=240 and 2 remaining numbers.

  8. #8
    Registered User
    Join Date
    12-25-2021
    Location
    Riyadh
    MS-Off Ver
    365
    Posts
    6

    Re: How To Find Maximum Sum From The List With nth Number of Values Not Greater Than To X

    The goal is to sum-up the highest totals first like 87 + 86 + 66 = 239 so it is the best combination and once this 87 (i.e cell A1) is used so this cell A1 should not be used again for addition in other combinations. as in image above. and so on for other cells.
    Remember that in image above (with red rectangle) i want to be like this, but now the macro is not working as image. i want to do same as image
    Last edited by shersalafi; 12-25-2021 at 11:51 AM.

  9. #9
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: How To Find Maximum Sum From The List With nth Number of Values Not Greater Than To X

    I think this is a classic "cutting" problem.

    see attachment, i give >105.000 solutions with 18 digit divided over 4*4.
    Of them there are 120 of which the smallest partition = 103

    So , that's the frustatican part of the answer.
    What's the "best" solution ???

    Lucky it was Christmas, the computer calculated this workbook, while i was busy.

    Edit : file too big.

  10. #10
    Registered User
    Join Date
    12-25-2021
    Location
    Riyadh
    MS-Off Ver
    365
    Posts
    6

    Re: How To Find Maximum Sum From The List With nth Number of Values Not Greater Than To X

    i want to create a macro according to the image which I have uploaded above.
    i want 3 or 4 values and those values or cells which are used in one sum should not be repeated. that's it.

  11. #11
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: How To Find Maximum Sum From The List With nth Number of Values Not Greater Than To X

    when i looked to the "cross-posted" site, it's indeed a cutting problem.
    this recent question is almost the same problem https://www.excelforum.com/excel-gen...izes-cuts.html
    I didn't check the given solution in relation to your problem.
    Normally you can also use "solver" or the newer version for those problems

    As what you asked, I can give you 616 different cut solutions, see sheet "Blad3", of which i think solution 298 is the "best".
    Of the 6st wood, you only use 103 of the 240 (cm?).

    So you asked me an image, i give you 616 images.

    Perhaps look to the other thread and ask help to "Davesexcel" or "Alf"
    Attached Files Attached Files
    Last edited by bsalv; 12-26-2021 at 10:46 AM.

  12. #12
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,236

    Re: How To Find Maximum Sum From The List With nth Number of Values Not Greater Than To X

    What i need is to sum up any 3 or 4 values that can be near to 240 but not more than that

    Not going to spend to much time on this...This is my take...
    Please Login or Register  to view this content.
    i need exactly as below in image.
    I do not get your combinations though...

    Untitled.png
    Attached Files Attached Files
    Last edited by sintek; 12-26-2021 at 12:52 PM.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  13. #13
    Registered User
    Join Date
    12-25-2021
    Location
    Riyadh
    MS-Off Ver
    365
    Posts
    6

    Re: How To Find Maximum Sum From The List With nth Number of Values Not Greater Than To X

    Thanks sintek, Thats i want and you nailed it. Thanks and big Thumbs up

  14. #14
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,236

    Re: How To Find Maximum Sum From The List With nth Number of Values Not Greater Than To X

    Pleasure...Glad I could contribute...
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Find maximum date with from range with last value greater than zero from next column
    By anotherbe01 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 01-27-2017, 07:31 PM
  2. Replies: 4
    Last Post: 12-05-2011, 07:01 PM
  3. Replies: 1
    Last Post: 05-17-2011, 08:44 PM
  4. Replies: 3
    Last Post: 07-07-2006, 09:10 PM
  5. Is there a maximum number of FIND functions?
    By ManosS in forum Excel General
    Replies: 1
    Last Post: 03-16-2006, 05:35 PM
  6. [SOLVED] How can I get Excel to find the first number in a list greater tha
    By krowlan in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-27-2005, 02:05 PM
  7. Replies: 0
    Last Post: 08-28-2005, 11:30 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1