I have a spreadsheet which uses MS Query to import data from our MRP System. This Spreadsheet has all new orders and qtys required per sales order etc. Each Part number may have several sales orders and different qtys for each. I am looking for help to write a fomula which looks the required qty`s for each sales order & part and check another sheet which has all the avaliable stock to sell on it and populate a column next to the qty req`d with what if anything is available.
Both the orders sheet and the stock sheet are MS Queries which refresh at a given interval so cells may change position.

Cutdown Example of Orders Sheet.

Sales Order No. ¦ Part ¦ Qty Req`d ¦
--------------------------------------
1234 ¦ Apple ¦ 12 ¦
6777 ¦ Apple ¦ 16 ¦
7989 ¦ Pear ¦ 4 ¦

cutdown Example of Stock Sheet.

Part ¦Qty in Stock ¦
----------------------
Apple ¦ 12 ¦
Pear ¦ 3 ¦


Now the fomula should bring back the following

Sales Order No. ¦ Part ¦ Qty Req`d ¦ Qty Avaliable ¦
----------------------------------------------------
1234 ¦ Apple ¦ 12 ¦ 12 ¦
6777 ¦ Apple ¦ 16 ¦ 0 ¦
7989 ¦ Pear ¦ 4 ¦ 3 ¦

Any Ideas?????

Regards
Alan