Hi guys. Is it possible for us to process a combinatorics problem from Excel?
For example, say I have 2 columns A & B. Column A contains 100 orders of quantities of items from 1-10 (with repetitions), and Column B contains rate per unit of that item. Let's say I set a parameter in which I say that the total no.of items required is 150. I want the output in two ways :
1. Total no.of combinations of item quantities possible that total up to 50 (10+10+10+10+10, 10+10+10+10+9+1, 10+8+2+10+10 and so on).
2. Output showing the break up of those combinations alongwith the corresponding average rate from those specified in column B.
Is this possible via a VBA code?
Input
[TABLE="width: 234"]
<tbody>[TR]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]Order quantities[/TD]
[TD="align: center"]Rates[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]12.25[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD="align: center"]11.30[/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD="align: center"]14.70[/TD]
[/TR]
[TR]
[TD="align: center"]4[/TD]
[TD="align: center"]10.55[/TD]
[/TR]
[TR]
[TD="align: center"]4[/TD]
[TD="align: center"]10.10[/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD="align: center"]9.85[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD="align: center"]10.80[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]11.95[/TD]
[/TR]
</tbody>[/TABLE]
Output parameter value = 10
Output
[TABLE="width: 148"]
<tbody>[TR]
[TD="width: 148"]No.of possible combinations : _____[/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="width: 534"]
<tbody>[TR]
[TD]List of combinations[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Quantities Combinations[/TD]
[TD]Average Rate[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4+4+2[/TD]
[TD="align: right"]10.17[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4+3+3[/TD]
[TD="align: right"]11.55[/TD]
[TD] (Picking up the value of 4 as 10.10)[/TD]
[/TR]
[TR]
[TD]4+3+3[/TD]
[TD="align: right"]11.70[/TD]
[TD] (Picking up the value of 4 as 10.55)[/TD]
[/TR]
[TR]
[TD]4+3+2+1[/TD]
[TD="align: right"]10.68[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4+2+2+1+1[/TD]
[TD="align: right"]11.37[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
It would be great if someone could come up with a VBA for this. Would save up a lot of manual time and labour.
For example, say I have 2 columns A & B. Column A contains 100 orders of quantities of items from 1-10 (with repetitions), and Column B contains rate per unit of that item. Let's say I set a parameter in which I say that the total no.of items required is 150. I want the output in two ways :
1. Total no.of combinations of item quantities possible that total up to 50 (10+10+10+10+10, 10+10+10+10+9+1, 10+8+2+10+10 and so on).
2. Output showing the break up of those combinations alongwith the corresponding average rate from those specified in column B.
Is this possible via a VBA code?
Input
[TABLE="width: 234"]
<tbody>[TR]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[/TR]
[TR]
[TD="align: center"]Order quantities[/TD]
[TD="align: center"]Rates[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]12.25[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD="align: center"]11.30[/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD="align: center"]14.70[/TD]
[/TR]
[TR]
[TD="align: center"]4[/TD]
[TD="align: center"]10.55[/TD]
[/TR]
[TR]
[TD="align: center"]4[/TD]
[TD="align: center"]10.10[/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD="align: center"]9.85[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD="align: center"]10.80[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]11.95[/TD]
[/TR]
</tbody>[/TABLE]
Output parameter value = 10
Output
[TABLE="width: 148"]
<tbody>[TR]
[TD="width: 148"]No.of possible combinations : _____[/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="width: 534"]
<tbody>[TR]
[TD]List of combinations[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Quantities Combinations[/TD]
[TD]Average Rate[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4+4+2[/TD]
[TD="align: right"]10.17[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4+3+3[/TD]
[TD="align: right"]11.55[/TD]
[TD] (Picking up the value of 4 as 10.10)[/TD]
[/TR]
[TR]
[TD]4+3+3[/TD]
[TD="align: right"]11.70[/TD]
[TD] (Picking up the value of 4 as 10.55)[/TD]
[/TR]
[TR]
[TD]4+3+2+1[/TD]
[TD="align: right"]10.68[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4+2+2+1+1[/TD]
[TD="align: right"]11.37[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
It would be great if someone could come up with a VBA for this. Would save up a lot of manual time and labour.