I am assuming that

i) All 9 products must be ordered

ii) That only N products must be ordered per product (that one is obvious)

iii) That we can fill the order from any of the houses A-C

iv) Data is stored in a 2 dimensional array

v) Arrays are 1 based

The simplest solution I can see is to allocate from houses successively until the quantity N is satisfied.

Dim product() ' Stores the required product quantity

Dim house() ' Stores the product number and quantity available

Dim houseOrder() ' Stores the amount to order from each house for each product

For prod = 1 to 9 (or variable holding number of products in the generic case)

QtyReq = product(prod)

indx = 1

do while order > 0

order = Min(QtyReq, house(prod, indx)

QtyReq = QtyReq - order

houseOrder(prod, indx) = order

indx = indx + 1

loop

next

This should leave the arrah houseOrder with the amounts that you want to order from each house.

That is the logic - have not tried to translate it into VBScript - not sure if you need help with the coding or just the algorithm.