+ Reply to Thread
Results 1 to 6 of 6

Excel Macro code (sum combination)

  1. #1
    Registered User
    Join Date
    09-16-2016
    Location
    Brazil
    MS-Off Ver
    2016
    Posts
    5

    Excel Macro code (sum combination)

    Hi there.

    I was suggested to open a new post for my question.

    I saw in other posts Macros for Excel that were created for something like what I need, but not exactly.
    So, the problem is: find all possible sums of sets of 6 numbers that fit in a range of min 180 and max of 191, in a list of 60 numbers.
    Example: 4 18 31 34 36 57 sum 180
    54 55 13 44 6 19 sum 191

    I use Excel 2016
    This topic is an exploration of this previous one - http://www.excelforum.com/excel-form...-formulas.html

    It would really help any clues, hope it helps others too.
    Cheers!
    Last edited by ocnerol; 09-20-2016 at 08:23 PM.

  2. #2
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Excel Macro code (sum combination)

    This sounds like maybe it's homework?

    If so: What code do you have so far? Or what pseudo-code? Or methods of approach?
    I'm interested in starting a career working with VBA, if anyone knows of any opportunities!

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Excel Macro code (sum combination)

    There are over a million such combinations. What would you do if you had them all?
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Registered User
    Join Date
    09-16-2016
    Location
    Brazil
    MS-Off Ver
    2016
    Posts
    5

    Re: Excel Macro code (sum combination)


  5. #5
    Registered User
    Join Date
    09-16-2016
    Location
    Brazil
    MS-Off Ver
    2016
    Posts
    5

    Re: Excel Macro code (sum combination)

    Homework ? More like a pastime
    the code started here
    http://www.excelforum.com/excel-form...-formulas.html

  6. #6
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: Excel Macro code (sum combination)

    The usual brute force strategy for generating combinations in a programming language like VBA is to use nested For..Next loops https://msdn.microsoft.com/en-us/lib...=vs.71%29.aspx
    Please Login or Register  to view this content.
    As shg notes, a brute force "generate all possible combinations" algorithm becomes prohibitively large fairly quickly, and limitations on computational resources, memory, and the like become restrictive.

    For interest, this is (obviously) not a new problem to computer science Wikipedia article: https://en.wikipedia.org/wiki/Subset_sum_problem . You might put something like "subset sum problem algorithm" into your favorite internet search engine and see what algorithms you can find. I think many of the algorithms are recursive (which does not work well in a spreadsheet, and VBA, I understand, is not the best language at recursion), so you might take that into consideration in your casual study of this problem.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

+ 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. need formula or vba for vlookup combination of trim code of 4 except 0
    By julielara in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-23-2016, 05:12 AM
  2. VBA code for MID MIN Find combination formula
    By redmarko in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-01-2015, 04:07 PM
  3. VBA code for a Combination Chart
    By smciesl2 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-13-2014, 03:33 PM
  4. Macro code needed for combination of (If,Countif,vlookup)
    By Dharmadme in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-20-2014, 03:58 PM
  5. VBA code for unique combination of 25 numbers take it 6
    By Basil2014 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-05-2014, 03:29 PM
  6. Reset Macro Button Code in combination with a Loop
    By tnuis in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-30-2013, 06:09 AM
  7. [SOLVED] Code equivelent to a key combination?
    By Conan Kelly in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-20-2005, 05:05 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