Combinatorics problem (VBA code)

adigada

New Member
Joined
Dec 18, 2014
Messages
2
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.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top