+ Reply to Thread
Results 1 to 7 of 7

Find a number combination in a group of cells

  1. #1
    Forum Contributor
    Join Date
    08-29-2011
    Location
    Minnesota
    MS-Off Ver
    Office 365
    Posts
    163

    Find a number combination in a group of cells

    I'm looking for another excel game changer (for the work I do anyway).

    I have a dollar amount, and I want to know if any combination of dollar amounts in a particular range of cells will equal that dollar amount. Is this possible in Excel?

    Example: I have 20 different dollar amounts in a column. I want to know what combination of those 20 different dollar amounts, if any, will equal $257.97. The dollar amount I'm looking for and the numbers in the range will change with each use. I'm hoping for a formula, but VBA will work too as I could just make a template and copy / paste the numbers in.

    I've come to learn to never doubt excel, but I have to admit that I'm having doubts on this one.

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Find a number combination in a group of cells

    Hi Opie,

    I did a problem like this a few months ago. See if the attached helps. If not then supply a sample file that we can work with to solve. To attach a sample, click on Go Advanced and then the Paper Clip Icon above the advanced message area.
    Attached Files Attached Files
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Find a number combination in a group of cells

    Question MarvinP, could you please explain why you use range "A2:A51" in your formula?

    I would have thought "A2:A50". I also did a test with solver but your solution works much faster!

    Alf

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Find a number combination in a group of cells

    Hi Alf,

    I guess I used A2 to A51 because that was how many numbers there were to pick from in the original problem. Feel free to change the ranges if more numbers are needed.

    I think we, as humans, get stuck on needing a formula to calculate things. Computers never get tired of guessing so I like doing random picks of numbers to see if they add up. In this problem it was a little different as the OP didn't say how many numbers needed to be used to sum to the total. I'm not sure my code did it correctly but the idea was still valid.

  5. #5
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Find a number combination in a group of cells

    you could just use solver
    Attached Files Attached Files
    Last edited by martindwilson; 10-29-2011 at 09:10 PM.
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  6. #6
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Find a number combination in a group of cells

    Thans for explanation MarvinP. Reason I asked was that changing the range A2:A51 in your formula to A2:A50 and running the macro gives me a #REF! value and I can't understand why.

    Alf

  7. #7
    Registered User
    Join Date
    03-15-2014
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: Find a number combination in a group of cells

    hey! i was wondering if it is possible to not get a combination from a certain group of cells... for instance, 1,2,-3 is not to be matched with each other; rather, they are to be matched against 5,3. Thus, leaving only 1,2 (from first group) and 5 (from the last group) as outstanding items. PS: i'm getting the combinations that:
    a. equal to zero
    b. from different groups/sets; and not with each other


    Thanks for your reply

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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