+ Reply to Thread
Results 1 to 4 of 4

VBA to Make Excel Find Combination of Numbers that Equal a Different Number

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

    VBA to Make Excel Find Combination of Numbers that Equal a Different Number

    Hi Everyone

    There are times when I have a payment from a customer without reference to what's being paid, and I then need to figure out what the customer is paying based on dollar amount. If I can't figure that out, then I call the customer, but I prefer to find it myself. I'm hoping that one of you fine individuals would be willing to make me a VBA code, assuming this could be done via VBA, to do this math for me.

    What I envision is a spreadsheet with three columns. Invoice numbers in A, dollar amounts in B, and the dollar amount I'm looking for in cell C1 or something. This is all editable if you need to move columns around for the code - I don't really care what information is in which column.

    What I'm hoping for is that I'll copy paste the invoice numbers and dollar amounts into the sheet, put the dollar amount I'm looking for in C1 (or wherever), and have excel run through every possible combination of adding invoice amounts and highlight the invoices it finds that add up to cell C1, assuming of course that such a combination exists. This could be anywhere from two invoices (rows) to 1,000.

    Is this something that VBA can do, and if so, is it something that one of you is willing to create for me?

    Thanks for your time!
    Last edited by OpieWinston; 03-11-2016 at 01:01 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: VBA to Make Excel Find Combination of Numbers that Equal a Different Number

    I have a workable solution, but the forum's not working right for me now in that I can't post the workbook, and the code doesn't make sense without the workbook. So instead of that let me point you to the places I developed my solution from:
    http://www.tushar-mehta.com/excel/te.../match_values/
    http://dailydoseofexcel.com/archives...sum-to-target/
    http://www.accountingweb.co.uk/anyan...me-numbers-add

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

    Re: VBA to Make Excel Find Combination of Numbers that Equal a Different Number

    Take a look at the startSearch Sub here:

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

    You could put 0 in A1, your payment amount in A2, then all your invoice values in A3:A whatever. After selecting that entire range, run startSearch. It will output all of the possible combos into column B.

    I must say this is pretty remarkable code, and all credit for it goes to Tushar Mehta.
    I'm interested in starting a career working with VBA, if anyone knows of any opportunities!

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

    Re: VBA to Make Excel Find Combination of Numbers that Equal a Different Number

    Thank you for the links - I'll give them a try!

+ 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: 8
    Last Post: 09-10-2015, 03:43 PM
  2. [SOLVED] Find combination of numbers that when added, equal a known value.
    By mgblair in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-09-2015, 08:45 PM
  3. Find numbers in a column that equal a number in a cell.
    By frankday in forum Excel General
    Replies: 5
    Last Post: 09-30-2014, 04:43 AM
  4. Combination of Numbers that equal a certain Sum
    By darkwinged in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-27-2012, 02:30 AM
  5. [SOLVED] Find a sum of a combination of cells to equal a value
    By Hervinder in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-11-2006, 11:40 AM
  6. Find the combination of numbers that when added equal a reqired total??
    By Handsy11 in forum Excel Formulas & Functions
    Replies: 41
    Last Post: 09-06-2005, 03:05 PM
  7. [SOLVED] Excel: Which numbers in a column equal a certain number (withou.
    By Pax in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-06-2005, 12:08 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