Skip to main content

How to find all combinations that equal a given sum in Excel?

For example, I have the following list of numbers, and now, I want to know which combination of numbers in the list sum up to 480, in the following screenshot shown, you can see there are five groups of possible combinations that add up equal to 480, such as 300+60+120, 300+60+40+80, etc. This article, I will talk about some methods to find which cells sum up to a specific value in Excel.


Find cells combination that equal a given sum with formulas

First, you need to create some range names, and then apply an array formula to find the cells that sum to the target value, please do with the following step by step:

1. Select the number list and define this list a range name-- Range1 into the Name Box, and press Enter key to finish the range name defined, see screenshot:

2. After defining a range name for the number list, then you need to create two further range names in the Name Manager box, please click Formulas > Name Manager, in the Name Manager dialog box, click New button, see screenshots:

3. In the popped out New Name dialog, enter a name List1 into the Name field, and type this formula =ROW(INDIRECT("1:"&ROWS(Range1))) (Range1 is the range name you have created in step1) into the Refers to field, see screenshot:

4. Click OK to return to the Name Manager dialog, then continue to click New button to create another range name, in the New Name dialog, enter a name List2 into the Name field, and type this formula =ROW(INDIRECT("1:"&2^ROWS(Range1))) (Range1 is the range name you have created in step1) into the Refers to field, see screenshot:

5. After creating the range names, please apply the following array formula into cell B2:

=IF(ISNUMBER(MATCH(ROWS($1:1),IF(INDEX(MOD(INT((List2-1)/2^(TRANSPOSE(List1)-1)),2),MATCH(TRUE,MMULT(MOD(INT((List2-1)/2^(TRANSPOSE(List1)-1)),2),Range1)=$C$2,0),),TRANSPOSE(List1)),0)),"X",""), and press Shift + Ctrl + Enter keys together, then drag the fill handle down to cell B8, the last number of the list, and you can see the numbers which total amount is 480 are marked as X in column B, see screenshot:

  • Notes:
  • In the above long formula: List1, List2 and Range1 are the range names you have created in former steps, C2 is the specific value that you want numbers added up to.
  • If more than one combination of values has a sum equal to the specific value, only one combination is listed.

Find and list all combinations that equal a given sum quickly and easily in Excel

Kutools for Excel's Make Up A Number utility can help you to find and list all combinations and specific combinations that equal to a given sum number quickly and easily. Click to download Kutools for Excel!

Kutools for Excel: with more than 300 handy Excel add-ins, free to try with no limitation in 30 days. Download and free trial Now!


Find cells combination that equal a given sum with Solver Add-in

If you are confused with above method, Excel contains a Solver Add-in feature, by using this add-in, you can also identify the numbers which total amount equals a given value.

1. First, you need to activate this Solver add-in, please go to File > Options, in the Excel Options dialog box, click Add-Ins from the left pane, and then click Solver Add-in from the Inactive Application Add-ins section, see screenshot:

2. Then click Go button to enter the Add-Ins dialog, check Solver Add-in option, and click OK to install this add-in successfully.

3. After activating the Solver add-in, then you need to enter this formula into the cell B9: =SUMPRODUCT(B2:B9,A2:A9), (B2:B9 is a blank column cells beside your number list, and A2:A9 is the number list that you use. ), and press Enter key, see screenshot:

4. Then click Data > Solver to go to the Solver Parameter dialog box, in the dialog, please do the following operations:

(1.) Click  button to select the cell B10 where your formula in from the Set Objective section;

(2.) Then in the To section, select Value Of, and enter your target value 480 as you need;

(3.) Under the By Changing Variable Cells section, please click button to select cell range B2:B9 where will mark your corresponding numbers.

5. And then click Add button to go to the Add Constraint dialog box, click button to select cell range B2:B9, and select bin from the drop down list, see screenshot:

6. Click OK to go back the Solver Parameter dialog, then click Solve button, some minutes later, a Solver Results dialog box is popped out, and you can see the combination of cells which equal a given sum 480 are marked as 1. In the Solver Results dialog, please select Keep Solver Solution option, and click OK to exit the dialog. See screenshot:

Note: This method is also only can get one combination cells if there are more than one combination of values has a sum equal to the specific value.


Find cells combination that equal a given sum with User Defined Function

The first two methods are all complex for most of our Excel users, here, I can create a VBA code to solve this job quickly and easily.

To get the correct result, you must sort the number list in descending order first. And then do with the following steps:

1. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.

2. Click Insert > Module, and paste the following code in the Module Window.

VBA code: Find cells combination that equal a given sum:

Function GetCombination(CoinsRange As Range, SumCellId As Double) As String
'updateby Extendoffice
    Dim xStr As String
    Dim xSum As Double
    Dim xCell As Range
    xSum = SumCellId
    For Each xCell In CoinsRange
        If Not (xSum / xCell < 1) Then
            xStr = xStr & Int(xSum / xCell) & " of " & xCell & "  "
            xSum = xSum - (Int(xSum / xCell)) * xCell
        End If
    Next
    GetCombination = xStr
End Function

3. Then save and close this code window, and then go back to the worksheet, and enter this formula =getcombination(A2:A9,C2) into a blank cell, and press Enter key, you will get the following result which displays the combination numbers that equal a given sum, see screenshot:

  • Notes:
  • In the above formula, A2:A9 is the number range, and C2 contains the target value you want to equal to.
  • If more than one combination of values has a sum equal to the specific value, only one combination is listed.

Find all combinations that equal a given sum with an amazing feature

Maybe all of the above methods are somewhat difficult for you, here, I will introduce a powerful-tool, Kutools for Excel, with its Make Up A Number feature, you can quickly get all combinations that equal to a given sum.

Tips:To apply this Make Up A Number feature, firstly, you should download the Kutools for Excel, and then apply the feature quickly and easily.

After installing Kutools for Excel, please do as this:

1. Click Kutools > Content > Make Up A Number, see screenshot:

2. Then, in the Make up a number dialog box, please click button to select the number list that you want to use from the Data Source, and then enter the total number into the Sum textbox, see screenshot:

3. And then, click OK button, a prompt box will pop out to remind you to select a cell to locate the result, see screenshot:

4. Then, click OK, and now, all combinations that equal to that given number have been displayed as below screenshot shown:

Click to Download Kutools for Excel and free trial Now!


Demo: Find cells combination that equal a given sum in Excel

Best Office Productivity Tools

Supports Office/Excel 2007-2021 and 365  |  Available in 44 Languages  |  Easy to Uninstall Completely

Popular Features: Find/Highlight/Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns     Move Columns   |   Unhide Columns   |   Compare Columns to Select Same & Different Cells ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more

Kutools for Excel Boasts Over 300 Features, Ensuring That What You Need Is Just A Click Away...

Supercharge Your Excel Skills: Experience Efficiency Like Never Before with Kutools for Excel  (Full-Featured 30-Day Free Trial)

kte tab 201905

60-Day Unconditional Money-Back GuaranteeRead More... Free Download... Purchase... 

Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day! (Full-Featured 30-Day Free Trial)
60-Day Unconditional Money-Back GuaranteeRead More... Free Download... Purchase... 
 
Comments (49)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hi everyone,

I'm trying to find a way to to find all possible combinations of workershifts for a specific amount of workhours within a specific amount of working days.

Both, solver and Kutools basically work, but:

Solver only ever displays one combination not all of them (which is what I would need).

Kutools on the other hand only uses each value once, for example I know there are solutions with say 3 7-hour shifts but it won't pick the shift more than once.

Thanks in advance for any responses!

Hope I'm not threadnecroing too hard here.
This comment was minimized by the moderator on the site
Hello, simsok,
Sorry, I can't understand you clearly.
Could you give your problem more detailed, or can you insert a screenshot of your problem here?
Thank you!
This comment was minimized by the moderator on the site
Thank you so much!!! The solver add-in worked for me!
This comment was minimized by the moderator on the site
How to get list of cell names that add to a given no.
This comment was minimized by the moderator on the site
Hello, Ranka,
I'm sorry, at present, there is no good way for getting the cells that add to a given number.
Thank you!
This comment was minimized by the moderator on the site
ExtendOffice - How To Find All Combinations That Equal A Given Sum In Excel

In this example, I would like to run 100 rows instead of the 8 in your example. When I try to create more rows the formula stops working. I started over with a fresh sheet and I still can not get the formula to work.

Running windows 10
Excel 2207
Office 365
This comment was minimized by the moderator on the site
Hello, Shaw

Unfortunately, the formula in this article has a limit of 20 values, if there are more than 20 numbers, the result will not come out. In this case, I will recommend the Make Up A Number feature of Kutools for Excel, with it, you can find all combinations from the list of numbers. If you have a lot of numbers and many combination results, it will take much time, but you can set the number of combinations to make it faster. See screenshot:
https://www.extendoffice.com/images/stories/comments/comment-skyyang/doc-make-up-number-1.png

You can download this tool from here: https://www.extendoffice.com/download/kutools-for-excel.html
You can try it for free 30 days, please have a try, hope it can help you!
This comment was minimized by the moderator on the site
Hi I have tried doing this with the first method and it just isn't working. I'm unsure what I'm doing wrong as I seem to have followed the instructions exactly. Are there any common errors to watch out for? There is no error showing in the formula itself and all cells are all in the same position as yours are, but it's a list of 48 numbers rather than 8.
This comment was minimized by the moderator on the site
Hello, Angie
If you can't get the result by using the first method, you can view the video at the bottom of this article:
https://www.extendoffice.com/documents/excel/3557-excel-find-all-combinations-that-equal-given-sum.html#demo
Also, you can try our tool-Kutools for Excel's Make up a number feature, it will get all combinations quickly and easily.
Thank you!
This comment was minimized by the moderator on the site
So will any of these work when I have been paid by a client, but with no remit so don’t know which invoices have been paid.
This comment was minimized by the moderator on the site
For the solver add in on excel, can you make it solve for closest to 480 rather than value of 480 (example used above)? I really need some help on how this might work out, thanks in advance

This comment was minimized by the moderator on the site
Could this be adapted to find combinations that sum up to specific range i.e. sum between 450 and 500? Is there a way to set it so that each cell value can be used only in one combination not more?
This comment was minimized by the moderator on the site
kutools works only integer value. Not support double. Like (395,52) ! Best solution is excel solver extention.
This comment was minimized by the moderator on the site
is there a way to find combination for a target average instead of sum ?
This comment was minimized by the moderator on the site
How come i can not use the Make up a Number in Kutools for numbers with decimals?
This comment was minimized by the moderator on the site
Hello, Jeremy,
So far, this Make up a number feature can not support the decimals, but, you can apply it with a workaround.
First, you can enlarge all the decimal numbers as whole numbers, such as multiply 100 to all the decimal numbers, and then apply this Make up a number feature, after getting the result, you should divide 100 to these numbers for returning them back to decimal numbers.
Please try it, hope it can help you!
This comment was minimized by the moderator on the site
How do you do for the list of numbers like 480
This comment was minimized by the moderator on the site
Thank you very much! Resolved my problem correctly.
This comment was minimized by the moderator on the site
Thank you so much for the VBA coding, it has solved a major headache trying to find combinations to equal an exact amount.
This comment was minimized by the moderator on the site
I have 1162 cells to find number x. Excel tells me that is too many variable cells. Very small data set! Any suggestions? Thanks!
This comment was minimized by the moderator on the site
Will the solver add-in not work if there are negative numbers in the list or if the value of number is 0? I'm trying to find a sum of numbers in a list that equate to zero with some numbers being negative and positive, but the solver does not work. I changed a couple numbers on my list to test to make sure I followed the steps correctly and it did work for the test. Please advise if there is a way to solve with negative and positive numbers to find a 0 value.
This comment was minimized by the moderator on the site
did you ever get an answer or did you find a way to do this?
This comment was minimized by the moderator on the site
Hello,
If there are both positive and negative numbers in the column, I recommend you apply the Kutools for Excel's Make up a number feature, it can solve your problem quickly and easily.

You can download Kutools for Excel and free trial 60 days. Please try!
This comment was minimized by the moderator on the site
Hello,
Thanks this is very good,
How can find the most approximate combinations if there is no exact value.
Many thanks
This comment was minimized by the moderator on the site
Hello,
Many thanks for information;
How can find the most approximate combinations if there is no exact value.
Many thanks,
This comment was minimized by the moderator on the site
Would somebody know how to adjust the VBA Getcombination function so that no repetition should be allowed?

For example, for numbers 1,2,3,4,5,13 if 14 is to be achieved than 1,13 is a solution, and not 14 of 1.
This comment was minimized by the moderator on the site
Function GetCombination(CoinsRange As Range, SumCellId As Double) As String
'updateby Extendoffice 20160506
Dim xStr As String
Dim xSum As Double
Dim xCell As Range
xSum = SumCellId
For Each xCell In CoinsRange
If Not (xSum / xCell < 1) Then
xStr = xStr & "1 of " & xCell & " "
xSum = xSum - xCell
End If
Next
GetCombination = xStr
End Function
This comment was minimized by the moderator on the site
Hi Ram, this works fine but doesnot give the actual sum.
EX: if i have 23,34,25,28,10,17&12 and i have a sum of 80(which is the sum of 23,28,17&12), I need a vba code which can find this combination (sum of 23,28,17&12) Can you please help me with this ?
This comment was minimized by the moderator on the site
hi it is giving me ambigious name error for the vba code
any help cause i know nothing in VBA
This comment was minimized by the moderator on the site
does anyone know if this works on google sheets
This comment was minimized by the moderator on the site
Yes there is an extension similar to excel's solver called "solver"
This comment was minimized by the moderator on the site
Hi,

My drouble with this formula is that it gives me one value for enough times to get the target value..
In the list of different values there are some values which are equal to each other.

E.g. I have 0,16 for 3 times(the first values in the list) and the formula gives me the answer that my target value is 593 of 0,16.

Why does it not combine different values to get my target value? It only chooses one value and gives how many times it is to be the target value.

Any help or idea?


Thanks!
This comment was minimized by the moderator on the site
I am trying to determine the best blend of product and am unsure if this is the best way to do it. At most I use three products in a blend with 5 specifications each. All of the specifications are linear and can be averaged when blended. One blend is usually 45,000lbs and each batch is 30,000lbs. Most of the time our blends are 15k+30k but I would like to be able to calculate for the unusual blends using the increments all the way down to 2000lbs.
This comment was minimized by the moderator on the site
The macro didn't work if there are more than one solution.
Also, I didn't work if I find "0"
This comment was minimized by the moderator on the site
Hello,Lorena,
Before applying the above VBA code, you must sort the number list in descending order first.
Second, the code is not work correctly to get the total number 0.
Hope it can help you, thank you!
This comment was minimized by the moderator on the site
Could you upload the excel?
This comment was minimized by the moderator on the site
Brilliant!!!
This comment was minimized by the moderator on the site
I was able to get the example with Range1 to work with my range in 12 rows, but when I changed the range to 42 rows it did not work. I even restarted the entire process with the 42 row version and that didn't work either. Any ideas?
This comment was minimized by the moderator on the site
HI, I downloaded Kutools but cannot get it to find all the combos less than a specified total.
This comment was minimized by the moderator on the site
Hi. The formula version didn't work for me either. It feels like it is missing a step. I do not see where the number specified in cell C2 comes into the formula.

Thanks
This comment was minimized by the moderator on the site
Hello, Dori,


There is no formula in C2, it is just the specific value that you want numbers added up to.
This comment was minimized by the moderator on the site
how if i need more than one combination? thank you
This comment was minimized by the moderator on the site
I'm at best a advanced beginner at Excel. I tried everything and it didn't work. What could I be doing wrong?
This comment was minimized by the moderator on the site
Awesome. Couldn't get the large formula to work but the solver add-in worked perfectly. Saved me so much work.
This comment was minimized by the moderator on the site
but it takes too much time
This comment was minimized by the moderator on the site
Is there a way to expand the range as Thom says, to say up to 50 numbers, but to also only total six of the numbers out of the range that sum to the specified total? Currently it will provide all combinations that total to the specified total. thanks
This comment was minimized by the moderator on the site
Superb Man!!! Superb Man!!!
This comment was minimized by the moderator on the site
Is there a way to expand the range so that it includes more than 8 numbers? Also, I'm not sure how this function is working: "=ROW(INDIRECT("1:"&2^ROWS(Range1)))". If I try to expand "Range1" beyond 15 rows, I get an #Ref error. It works great with just the 8 numbers, but what if you wanted to include, say, 50 numbers or even 100.
This comment was minimized by the moderator on the site
Same issue
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations