Script to subtract quantities in two sheets with multiple conditions

BrutalDawg

New Member
Joined
Jun 10, 2015
Messages
41
I have spent the last few hours trying to find something similar to the issue I am having and currently have smoke coming out of my ears!
I have two sheets, one with orders the second with sales.
I need help automatically subtracting from orders based on sales.
I am trying to develop a script that would run through every sale and if location and item are exactly the same, subtract quantity sold from the quantity ordered to give a "new due" quantity.
There will be sales with no order which is a non issue, but would be nice if those results could go to a different tab. Below is a summary of what is required in n00b terms.
<code style="margin: 0px; padding: 1px 5px; border: 0px; font-size: 13px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; background-color: rgb(239, 240, 241); white-space: pre-wrap;">Sheet1</code> is sold, <code style="margin: 0px; padding: 1px 5px; border: 0px; font-size: 13px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; background-color: rgb(239, 240, 241); white-space: pre-wrap;">Sheet2</code> is order.
If <code style="margin: 0px; padding: 1px 5px; border: 0px; font-size: 13px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; background-color: rgb(239, 240, 241); white-space: pre-wrap;">Sheet1</code> C2 & F2 are same as any row in <code style="margin: 0px; padding: 1px 5px; border: 0px; font-size: 13px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; background-color: rgb(239, 240, 241); white-space: pre-wrap;">Sheet2</code> (A2,D2 are correlating fields) subtract <code style="margin: 0px; padding: 1px 5px; border: 0px; font-size: 13px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; background-color: rgb(239, 240, 241); white-space: pre-wrap;">Sheet1</code>G2, from <code style="margin: 0px; padding: 1px 5px; border: 0px; font-size: 13px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; background-color: rgb(239, 240, 241); white-space: pre-wrap;">Sheet2</code> F2.

ABCDEFG
1TypeDateShip To Address 1Ship To Address 2Ship ZipItemQty
2Invoice1/25/2017Ohio569860
3Invoice1/25/2017Oklahoma569350
4Invoice1/24/2017TEXAS5701220
5Invoice1/25/2017TEXAS5699112
6Invoice1/26/2017Florida572920
7Invoice1/25/2017Oklahoma5693205
8Invoice1/25/2017Mexico5695165
9Invoice1/25/2017Ohio569845

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sold



ABCDEFG
1PlantIssueDatePurchaseOrderNumberPartNumberTimingQuantityWhen
2Texas1/22/2017AI437BD1843Immediate:Discrete131/22/2017
3Oklahoma1/22/2017AI589AD1852Firm:Weekly Bucket (Monday through Sunday)281/23/2017
4Texas1/22/2017AI437BD1876Firm:Weekly Bucket (Monday through Sunday)91/23/2017
5Texas1/22/2017AI437BD1843Firm:Weekly Bucket (Monday through Sunday)1741/23/2017
6Oklahoma1/22/2017AI589AD1882Firm:Weekly Bucket (Monday through Sunday)31/30/2017
7Oklahoma1/22/2017AI589AD1852Firm:Weekly Bucket (Monday through Sunday)2051/30/2017
8Texas1/22/2017AI437BD1876Firm:Weekly Bucket (Monday through Sunday)31/30/2017
9Texas1/22/2017AI437BD1843Firm:Weekly Bucket (Monday through Sunday)1101/30/2017
10OHIO1/22/2017AI589AD1874Firm:Weekly Bucket (Monday through Sunday)601/30/2017
11OHIO1/22/2017AI589AD1852Firm:Weekly Bucket (Monday through Sunday)421/30/2017
12Mexico1/22/2017AI437BD1876Firm:Weekly Bucket (Monday through Sunday)11/30/2017
13Mexico1/22/2017AI589AD1852Firm:Weekly Bucket (Monday through Sunday)1641/30/2017
14Oklahoma1/22/2017AI589AD1882Firm:Weekly Bucket (Monday through Sunday)22/6/2017
15Oklahoma1/22/2017AI589AD1852Firm:Weekly Bucket (Monday through Sunday)2042/6/2017
16Texas1/22/2017AI437BD1876Firm:Weekly Bucket (Monday through Sunday)62/6/2017
17Texas1/22/2017AI437BD1843Firm:Weekly Bucket (Monday through Sunday)1882/6/2017
18OHIO1/22/2017AI589AD1874Firm:Weekly Bucket (Monday through Sunday)602/6/2017
19OHIO1/22/2017AI589AD1852Firm:Weekly Bucket (Monday through Sunday)2992/6/2017
20Mexico1/22/2017AI437BD1876Firm:Weekly Bucket (Monday through Sunday)32/6/2017
21Mexico1/22/2017AI589AD1852Firm:Weekly Bucket (Monday through Sunday)1972/6/2017
22Oklahoma1/22/2017AI589AD1882Firm:Weekly Bucket (Monday through Sunday)102/13/2017
23Oklahoma1/22/2017AI589AD1852Firm:Weekly Bucket (Monday through Sunday)1662/13/2017
24Texas1/22/2017AI437BD1876Firm:Weekly Bucket (Monday through Sunday)42/13/2017

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Order



ABCDEFGH
1PlantIssueDatePurchaseOrderNumberPartNumberTimingQuantityWhen
2TEXAS1/22/2017D1843Immediate:Discrete-2991/22/20170
3Oklahoma1/22/2017D1852Firm:Weekly Bucket (Monday through Sunday)-1771/23/20170
4TEXAS1/22/2017D1876Firm:Weekly Bucket (Monday through Sunday)91/23/2017
5TEXAS1/22/2017D1843Firm:Weekly Bucket (Monday through Sunday)1741/23/2017-45
6Oklahoma1/22/2017D1882Firm:Weekly Bucket (Monday through Sunday)-471/30/20170
7Oklahoma1/22/2017D1852Firm:Weekly Bucket (Monday through Sunday)2051/30/201728
8TEXAS1/22/2017D1876Firm:Weekly Bucket (Monday through Sunday)31/30/2017
9TEXAS1/22/2017D1843Firm:Weekly Bucket (Monday through Sunday)1101/30/2017
10OHIO1/22/2017D1874Firm:Weekly Bucket (Monday through Sunday)01/30/2017
11OHIO1/22/2017D1852Firm:Weekly Bucket (Monday through Sunday)-31/30/20170
12Mexico1/22/2017D1876Firm:Weekly Bucket (Monday through Sunday)11/30/2017
13Mexico1/22/2017D1852Firm:Weekly Bucket (Monday through Sunday)1641/30/2017
14Oklahoma1/22/2017D1882Firm:Weekly Bucket (Monday through Sunday)22/6/2017
15Oklahoma1/22/2017D1852Firm:Weekly Bucket (Monday through Sunday)2042/6/2017
16TEXAS1/22/2017D1876Firm:Weekly Bucket (Monday through Sunday)62/6/2017
17TEXAS1/22/2017D1843Firm:Weekly Bucket (Monday through Sunday)1882/6/2017
18OHIO1/22/2017D1874Firm:Weekly Bucket (Monday through Sunday)602/6/2017
19OHIO1/22/2017D1852Firm:Weekly Bucket (Monday through Sunday)2992/6/2017296
20Mexico1/22/2017D1876Firm:Weekly Bucket (Monday through Sunday)32/6/2017
21Mexico1/22/2017D1852Firm:Weekly Bucket (Monday through Sunday)322/6/2017
22Oklahoma1/22/2017D1882Firm:Weekly Bucket (Monday through Sunday)102/13/2017(-37)
23Oklahoma1/22/2017D1852Firm:Weekly Bucket (Monday through Sunday)1662/13/2017
24TEXAS1/22/2017D1876Firm:Weekly Bucket (Monday through Sunday)42/13/2017
25TEXAS1/22/2017D1882Firm:Weekly Bucket (Monday through Sunday)1102/20/201765
26WOULD BE IDEAL RESULT FOR (F)

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Results




On the results tab everything highlighted in yellow is what would have changed. Items not highlighted in yellow there was no sale. The green and red formatting was for reference and is not required if to difficult. (would be ideal) column H, is illustrating, if this is even possible, once the order quantity reaches 0, for the script to keep searching sheet for next order with same criteria and subtract remain quantity. Anything will help, I am currently doing this manually over the weekend and generally 150+ sales per week and is very time consuming.

In simple terms, I am trying to have a script go through each sale row and subtract quantity from the order sheet if the plant and part number are the same. I will sort the order sheet based on when they are do so it removes from correct order.

Thanks for any help!

 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,215,754
Messages
6,126,680
Members
449,328
Latest member
easperhe29

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