For example:
I've got a value of 15 and I want to see what 9 number values can go into 15. By hand I generate it this way:
(Note: Maximum Value can be 5 (Increments bigger later on), Minimum Value can be 0)
| 5 | 5 | 5 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|
| 5 | 5 | 4 | 1 | 0 | 0 | 0 | 0 | 0 |
| 5 | 5 | 3 | 2 | 0 | 0 | 0 | 0 | 0 |
| 5 | 5 | 3 | 1 | 1 | 0 | 0 | 0 | 0 |
As you can see this can be tedious to do long hand. Especially considering that I have to do this for values 15 - 51.
I've been using the Transpose function to transpose arrays I've created before, but that was to transpose an array into a Random order:
=TRANSPOSE(SORTN(TRANSPOSE(B22:I22),8,,RANDARRAY(8),))
Looking for an Excel answer I came across this, but it uses an Add-On to do so:
https://www.extendoffice.com/documents/excel/3557-excel-find-all-combinations-that-equal-given-sum.html
Why I'm doing this?
I'm personally creating a character generator for Chronicles of Darkness Generic Monsters. Monster traits are numeric values with a trait limit of 5 at Lvl 1 which goes up to 10 at lvl 6 and doesn't increase from lvl 6 to 10. The total value of traits to distribute at lvl 1 is between 15-18, 19-22 at Lvl 2, 23-26 at lvl 3, etc... increasing by 4 each level till lvl 10 where its anything over 51 (But this doesn't have to be included in my generator).
If you have any questions feel free to ask.
If A2:A18 had the 17 numbers,
B1(heading):
=TRANSPOSE(A2:A18)
B2:
=ARRAYFORMULA(A2:A18+TRANSPOSE(A2:A18))
This will give a 17*17 table of SUM of all different combinations:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
If all you need are pairs of values, then use this simpler macro:
Sub PairsOnly()
Dim Items(1 To 17) As Variant
Dim i As Long, j As Long, k As Long
Dim lower As Long, upper As Long
lower = LBound(Items)
upper = UBound(Items)
k = 2
For i = lower To upper
Items(i) = Cells(1, i)
Next i
For i = lower To upper - 1
For j = i + 1 To upper
Cells(k, 1) = Items(i) & "," & Items(j)
Cells(k, 2) = Items(i) + Items(j)
k = k + 1
Next j
Next i
End Sub

google sheets - Combinations to find a given sum - Web Applications Stack Exchange
Find combinations of number that add up to a specified sum in google sheets - Stack Overflow
Google Sheets - Indicate which cells sum a value - Google Docs Editors Community
find a combination of numbers that equal a given sum
What is the SUM function in Google Sheets?
How to use the SUM formula in Google Sheets?
Why is the SUM formula beneficial in Google Sheets?
Videos
Please bear with me as I try my best to explain what I'm trying to do...
I want to analyze some data from a video game. The player can equip four types of armor, and each piece of armor has an associated weight value. A simplified example of the data table I'm working with is below.
| A | B | C | D | E | F | G | H | |
|---|---|---|---|---|---|---|---|---|
| 1 | Head | Helm Weight | Chest | Chest Weight | Arms | Arms Weight | Legs | Legs Weight |
| 2 | Bare head | 0.0 | Bare chest | 0.0 | Bare arms | 0.0 | Bare legs | 0.0 |
| 3 | Hat | 0.5 | Shirt | 1.0 | Gloves | 0.5 | Socks | 0.1 |
| 4 | Helmet | 3.0 | Jacket | 2.0 | Boots | 1.0 | ||
| 5 | Armor | 10.0 |
I'd like to generate a list of all possible combinations of gear that the player can wear, and also find the total weight of all equipped pieces for each permutation. Unfortunately, each category has between 25-50 available items, which means the number of possible combinations is HUGE.
I found that the example here works well for generating the list of combinations. I slightly modified the formula to help separate and identify the items in the resulting string. It takes a long time for the list to fill in, but I think that's going to be a problem no matter what due to the sheer number of results.
=INDEX(FLATTEN(FLATTEN(FLATTEN("{{Head}}"&
FILTER(A2:A, A2:A<>"")&"{{Chest}}"&TRANSPOSE(
FILTER(C2:C, C2:C<>"")))&"{{Arms}}"&TRANSPOSE(
FILTER(E2:E, E2:E<>"")))&"{{Legs}}"&TRANSPOSE(
FILTER(G2:G, G2:G<>""))))The formula generates a list that looks like this:
{{Head}}Bare head{{Chest}}Bare chest{{Arms}}Bare arms{{Legs}}Bare legs
{{Head}}Bare head{{Chest}}Bare chest{{Arms}}Bare arms{{Legs}}Socks
{{Head}}Bare head{{Chest}}Bare chest{{Arms}}Bare arms{{Legs}}Boots
{{Head}}Bare head{{Chest}}Bare chest{{Arms}}Gloves{{Legs}}Bare legs
{{Head}}Bare head{{Chest}}Bare chest{{Arms}}Gloves{{Legs}}Socks
...Great, step one done. However, once the list is made, I don't know the most efficient way to look up and find the sum of the weights for each combination. I can extract each item from the combined string with some MID and FIND manipulation, and then use VLOOKUP or INDEX/MATCH to get the associated weights, then add them all together. But the formula is clunky and significantly adds to the sheet's already long processing time. A smaller test sample set eventually outputs the information I need, but with the full set of data the sheet takes several minutes to load and eventually crashes. I know for sure that my sheet has enough rows for the list to expand into, so that's not the issue.
I also found this example of a script that does more or less the same thing as the INDEX/FLATTEN/FILTER/TRANSPOSE formula. I thought it might be faster, but testing with a shorter list results in "result too large" error message, so it won't be able to handle my full list. Even if it could handle it, the script assumes all four columns have the same number of rows, so it would still need to be modified. And besides, this doesn't address my need for a better way to extract and add up the weights of each possible combination.
Does anyone have a better idea how to process this mass of information? Is there a better set of formulas I should be using or scripts that can handle my needs without bogging down the sheet to the point that it's unusable?