+ Reply to Thread
Results 1 to 8 of 8

VBA: All combinations that sum between two numbers - too much processing blows it up

  1. #1
    Registered User
    Join Date
    05-01-2023
    Location
    United States
    MS-Off Ver
    16.72
    Posts
    4

    VBA: All combinations that sum between two numbers - too much processing blows it up

    Hi,

    Thanks much in advance for reading. It's really not an overly confusing concept, and I've tried to lay it out as simply as possible!

    I have some VBA code (not my own) that successfully returns combination sums between a defined range. A quick summary of what that even means, then my issue.

    Example: my range is 5 to 10. My number list is 1, 1, 3, 4, 9.

    VBA would return strings of 1,1,3 (sum of 5); 1,1,3,4 (sum of 9); 1,1,4 (sum of 6), and so on and so forth. Literally every unique combination that sums between 5 -10. It returns the string in a cell, moving down a row for every string. Lots of rows usually, I'm sure you can imagine.

    Hopefully that's simple enough to track.

    My problem is that I want to LIMIT the length of the strings it returns. I only want strings with 1-3 numbers included. So in my above example, the 1,1,3,4 (sum of 9) would preferably not return. Without this limitation, when my number lists get longer, Excel explodes due to having so many qualifying strings to return. I want to reduce the processing required - and only need the data from the smaller 1-3 number strings anyways.

    Any suggestions? I wish I was more familiar with VBA, and I've wasted a lot of time already trying to work it out myself as a layman..

    My main thought so far is adding a 3rd If statement in the 2nd paragraph of code that somehow accomplishes this.

    Tried uploading an example sheet but couldn't get it below 1MB for the life of me..

    Thanks

    Please Login or Register  to view this content.
    Last edited by usssssye; 05-07-2023 at 04:35 AM.

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

    Re: VBA: All combinations that sum between two numbers - too much processing blows it up

    add this "And Len(currentset) <= 6" in the last line here below .
    6 is 3 digits and 3 commas

    Please Login or Register  to view this content.
    Last edited by bsalv; 05-07-2023 at 05:10 AM.
    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
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2505 (Windows 11 Home 24H2 64-bit)
    Posts
    91,301

    Re: VBA: All combinations that sum between two numbers - too much processing blows it up

    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 told us about this. You are required to do so.

    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: https://excelguru.ca/a-message-to-forum-cross-posters/

    (Note: this requirement is not optional. As you are new here, I shall do it for you this time: https://www.mrexcel.com/board/thread...ws-up.1236547/)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2506 Win 11
    Posts
    24,791

    Re: VBA: All combinations that sum between two numbers - too much processing blows it up

    crosspost: https://www.mrexcel.com/board/thread...ws-up.1236547/

    Rule 03: Cross-posting Without Telling Us

    Your post does not comply with Rule 3 of our Forum RULES. Do not cross-post your question on multiple forums without telling us about your threads on other forums.

    Post a link to any other forums where you have asked the same question.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Read this to understand why we ask you to do this.

    I have added the crosspost reference for you today. Please comply with this and all our rules in the future

    However, if you continue to crosspost, you can expect to have your thread BLOCKED until you update it yourself.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  5. #5
    Registered User
    Join Date
    05-01-2023
    Location
    United States
    MS-Off Ver
    16.72
    Posts
    4

    Re: VBA: All combinations that sum between two numbers - too much processing blows it up

    Apologies on the cross-posting mistake, I'll keep this in mind moving forward. Thank you.

  6. #6
    Registered User
    Join Date
    05-01-2023
    Location
    United States
    MS-Off Ver
    16.72
    Posts
    4

    Re: VBA: All combinations that sum between two numbers - too much processing blows it up

    Bsalv - yes that does work! As I have numbers with decimals, things had to be altered a bit to focus on the commas for the LEN rather than the count of digits. But thank you so much for your help with this!

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

    Re: VBA: All combinations that sum between two numbers - too much processing blows it up

    for example, count the number of commas like this = max 3 sets of numbers
    Len(currentset) - Len(Replace(currentset, ",", "")) <= 3

  8. #8
    Registered User
    Join Date
    05-01-2023
    Location
    United States
    MS-Off Ver
    16.72
    Posts
    4

    Re: VBA: All combinations that sum between two numbers - too much processing blows it up

    Thank you!

+ 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. Replies: 1
    Last Post: 04-13-2021, 08:04 PM
  2. [SOLVED] To find all combinations of numbers from list of numbers that adds upto a specified number
    By Vivek2705 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-07-2019, 06:33 AM
  3. please help!!ALL COMBINATIONS REQUIRED FOR 5-DIGIT NUMBERs using numbers 0-9
    By natasha mirembe in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-08-2014, 01:43 PM
  4. Sheet-related processing causes Excel VBA Userform to stop processing Tab/Enter
    By Joaquin M Lopez Muno in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-22-2014, 03:02 PM
  5. Reduce processing time for processing multiple excel sheets
    By rexer231 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-06-2014, 09:25 AM
  6. Replies: 1
    Last Post: 04-15-2012, 09:23 AM
  7. [SOLVED] Add in blows up! Author disavows responsibility
    By Michael Conroy in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-18-2005, 10:06 AM

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