Forecast shortages

BrutalDawg

New Member
Joined
Jun 10, 2015
Messages
41
Hello,

I am trying to be able to better identify shortages without as many steps for other users that are not as fluent in excel. Currently, all I do is take my sales order filter down to 3-4 weeks and run a combination script:

Sub CombineRows()
'Updated 20150511
Dim WorkRng As Range
Dim Dic As Variant
Dim arr As Variant
On Error Resume Next
xTitleId = "Stock-INSERT-DATE-HERE"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Set Dic = CreateObject("Scripting.Dictionary")
arr = WorkRng.Value
For i = 1 To UBound(arr, 1)
Dic(arr(i, 1)) = Dic(arr(i, 1)) + arr(i, 2)
Next
Application.ScreenUpdating = False
WorkRng.ClearContents
WorkRng.Range("A1").Resize(Dic.Count, 1) = Application.WorksheetFunction.Transpose(Dic.keys)
WorkRng.Range("B1").Resize(Dic.Count, 1) = Application.WorksheetFunction.Transpose(Dic.items)
Application.ScreenUpdating = True
End Sub

Then I utilize a simple conditional formatting rule that highlights any item that is less than Stock. This creates a lot of leg work of verifying when the PO will deliver compared to the sales order. I am trying to develop a tool, where I can have the Sales Orders on Sheet1, Stock on Sheet2, and better identification of shortages. For example stock:

Item NumberQuantity
1a1200
2b2305

<tbody>
</tbody>


Example Sales Orders:
LocationPurchaseOrderNumberPart NumberTimingQuantityWhen
8001a1Planning5011/1/2016
7201a1Planning5011/1/2016
8002b2Planning10011/1/2016
80A437B1a1Planning5011/8/2016
72A8683B1a1Planning10011/8/2016
72A8932b2Planning5011/8/2016
6501a1Planning7511/15/2016
8002b2Planning7511/15/2016
65A437B2b2Planning10011/15/2016
80A78932b2Planning12011/22/2016
65B78201a1Planning10011/22/2016

<tbody>
</tbody>

with an example output of:
LocationPurchaseOrderNumberPart NumberTimingQuantityWhenShort Quantity
8001a1Planning5011/1/2016
7201a1Planning5011/1/2016
8002b2Planning10011/1/2016
80A437B1a1Planning5011/8/2016
72A8683B1a1Planning10011/8/201650
72A8932b2Planning5011/8/2016
6501a1Planning7511/15/20160
8002b2Planning7511/15/2016
65A437B2b2Planning10011/15/201620
80A78932b2Planning12011/22/20160
65B78201a1Planning10011/22/20160

<tbody>
</tbody>

Is this possible with the SO's having split quantities?

Thanks for any suggestions!
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
You may be able to do the shortages with a formula.

Put this in G2 and copy it down the column...

=IF(VLOOKUP(C2,Sheet1!A:B,2,0)< SUMIF($C$1:C2,C2,$E$1:E2),SUMIF($C$1:C2,C2,$E$1:E2)-VLOOKUP(C2,Sheet1!A:B,2,0),"")<sumif($c$1:c2,c2,$e$1:e2),sumif($c$1:c2,c2,$e$1:e2)-vlookup(c2,sheet1!a:b,2,0),"")< html=""></sumif($c$1:c2,c2,$e$1:e2),sumif($c$1:c2,c2,$e$1:e2)-vlookup(c2,sheet1!a:b,2,0),"")<>
 
Last edited:
Upvote 0
Try this:-
Stock on sheet2 (actual data starts "A2")
Sales Order on Sheet1 (actual Data starts "A2"
Code:
[COLOR="Navy"]Sub[/COLOR] MG31Oct42
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, P [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] Dic1 [COLOR="Navy"]As[/COLOR] Object, Q [COLOR="Navy"]As[/COLOR] Variant, Dic2 [COLOR="Navy"]As[/COLOR] Object, K [COLOR="Navy"]As[/COLOR] Variant
[COLOR="Navy"]With[/COLOR] Sheets("sheet2")
    [COLOR="Navy"]Set[/COLOR] Rng = .Range(.Range("A2"), .Range("A" & Rows.Count).End(xlUp))
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]Set[/COLOR] Dic1 = CreateObject("scripting.dictionary")
Dic1.CompareMode = vbTextCompare
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng: Dic1(Dn.Value) = Dn.Offset(, 1).Value: [COLOR="Navy"]Next[/COLOR]
[COLOR="Navy"]With[/COLOR] Sheets("Sheet1")
    [COLOR="Navy"]Set[/COLOR] Rng = .Range(.Range("C2"), .Range("C" & Rows.Count).End(xlUp))
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]Set[/COLOR] Dic2 = CreateObject("scripting.dictionary")
Dic2.CompareMode = vbTextCompare
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
   [COLOR="Navy"]If[/COLOR] Not Dic2.Exists(Dn.Value) [COLOR="Navy"]Then[/COLOR]
        Dic2.Add Dn.Value, Array(Nothing, Dn.Offset(, 2))
        [COLOR="Navy"]If[/COLOR] Dn.Offset(, 2) > Dic1(Dn.Value) [COLOR="Navy"]Then[/COLOR] [COLOR="Navy"]Set[/COLOR] Dic2(Dn.Value)(0) = Dn
    [COLOR="Navy"]Else[/COLOR]
        Q = Dic2(Dn.Value)
           Q(1) = Q(1) + Dn.Offset(, 2)
            [COLOR="Navy"]If[/COLOR] Q(1) > Dic1(Dn.Value) [COLOR="Navy"]Then[/COLOR]
              [COLOR="Navy"]If[/COLOR] Q(0) [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR]
                  [COLOR="Navy"]Set[/COLOR] Q(0) = Dn
              [COLOR="Navy"]Else[/COLOR]
                  [COLOR="Navy"]Set[/COLOR] Q(0) = Union(Q(0), Dn)
              [COLOR="Navy"]End[/COLOR] If
            [COLOR="Navy"]End[/COLOR] If
        Dic2(Dn.Value) = Q
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR]
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] K [COLOR="Navy"]In[/COLOR] Dic2.keys
    [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] P [COLOR="Navy"]In[/COLOR] Dic2(K)(0)
        P.EntireRow.Font.Color = vbRed
    [COLOR="Navy"]Next[/COLOR] P
 [COLOR="Navy"]Next[/COLOR] K
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Thanks Mick,

I am receiving Run-time error '424':
Object required.

When I debug I get For Each P In Dic2(K)(0)

I have notice it does not discover the first shortage. For example the request 200 pieces but only 150 are in stock, the next order is highlighted red not the original short.

Alpha - Your formula appears to work. Assuming #N/A means it is not found in stock. Is there a way you can remove all suffix's - such as a1a-exact to just a1a without having to find a replace each? There are about 60 or so with that suffix that constantly change.
 
Upvote 0
Would it be possible to add a rolling total to H? This way, with Alpha's formula I could add conditional formatting to highlight the entire row for better visibility.

Thanks for the help!
 
Last edited:
Upvote 0
Alpha - Your formula appears to work. Assuming #N/A means it is not found in stock. Is there a way you can remove all suffix's - such as a1a-exact to just a1a without having to find a replace each? There are about 60 or so with that suffix that constantly change.

Are the suffixes on the Sales Orders and not on Stock?
Do all suffixes start with a dash?
Is the item number always the first three characters?

Describe in detail the actual part numbers and the suffixes.


Suffixes aside, you can remove the #/N/A results by wrapping the formula in an IFERROR function
=IFERROR(formula, "No product match")
 
Upvote 0
Thank you that fixed the N/A problem.

The suffixes are on the stock only, used as an internal reference. The item numbers can be formatted differently depending on the customer, but in general it is a 7 digit number followed, followed by a revision. Examples:
1234567
9876543B1
2589631B81

However; the only suffix used is -exact for all items. -- It is a local reference to let users know it must be exact quantity. For example 1234567C1-exact .

Would it be possible to add a rolling total to H? As below: your formula in the G




LocationPurchaseOrderNumberPart NumberTiming QuantityWhenShort QuantityRolling Stock
8001A1Planning5011/1/2016150
7201a1Planning5011/1/2016100
8002b2Planning10011/1/2016205
80A437B1a1Planning5011/8/201650
72A8683B1a1Planning10011/8/201650-50
72A8932b2Planning5011/8/2016155
6501a1Planning7511/15/2016125-125
8002b2Planning7511/15/201680
65A437B2b2Planning10011/15/201620-20
80A78932b2Planning12011/22/2016140-140
65B78201A1Planning10011/22/2016225-225

<colgroup><col><col><col span="4"><col><col><col></colgroup><tbody>
</tbody>
 
Upvote 0
Mick,

This seems to work well. How would I utilize the code when I have new purchase orders, or stock? Is it possible to have a continuous stock count in cell H?
 
Upvote 0
Try this for "Rolling Stock" (column "H")
Code:
[COLOR="Navy"]Sub[/COLOR] MG01Nov28
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, Fd [COLOR="Navy"]As[/COLOR] Boolean
[COLOR="Navy"]Dim[/COLOR] Dic1 [COLOR="Navy"]As[/COLOR] Object, Q [COLOR="Navy"]As[/COLOR] Variant, Dic2 [COLOR="Navy"]As[/COLOR] Object, K [COLOR="Navy"]As[/COLOR] Variant
[COLOR="Navy"]With[/COLOR] Sheets("sheet2")
    [COLOR="Navy"]Set[/COLOR] Rng = .Range(.Range("A2"), .Range("A" & Rows.Count).End(xlUp))
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]Set[/COLOR] Dic1 = CreateObject("scripting.dictionary")
Dic1.CompareMode = vbTextCompare
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng: Dic1(Dn.Value) = Dn.Offset(, 1).Value: [COLOR="Navy"]Next[/COLOR]
[COLOR="Navy"]With[/COLOR] Sheets("Sheet1")
    [COLOR="Navy"]Set[/COLOR] Rng = .Range(.Range("C2"), .Range("C" & Rows.Count).End(xlUp))
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]Set[/COLOR] Dic2 = CreateObject("scripting.dictionary")
Dic2.CompareMode = vbTextCompare
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
   [COLOR="Navy"]If[/COLOR] Not Dic2.Exists(Dn.Value) [COLOR="Navy"]Then[/COLOR]
     Dic2.Add Dn.Value, Array(Dn.Offset(, 2), Fd)
        Q = Dic2(Dn.Value)
            Dn.Offset(, 5) = Dic1(Dn.Value) - Q(0)
            [COLOR="Navy"]If[/COLOR] Dn.Offset(, 2) > Dic1(Dn.Value) [COLOR="Navy"]Then[/COLOR]
                Dn.EntireRow.Font.Color = vbRed
                [COLOR="Navy"]If[/COLOR] Not Q(1) [COLOR="Navy"]Then[/COLOR] Dn.Offset(, 4) = Q(0) - Dic1(Dn.Value)
                Q(1) = True
            [COLOR="Navy"]End[/COLOR] If
        Dic2(Dn.Value) = Q
   [COLOR="Navy"]Else[/COLOR]
         Q = Dic2(Dn.Value)
            Q(0) = Q(0) + Dn.Offset(, 2)
            Dn.Offset(, 5) = Dic1(Dn.Value) - Q(0)
            [COLOR="Navy"]If[/COLOR] Q(0) > Dic1(Dn.Value) [COLOR="Navy"]Then[/COLOR]
                Dn.EntireRow.Font.Color = vbRed
                [COLOR="Navy"]If[/COLOR] Not Q(1) [COLOR="Navy"]Then[/COLOR] Dn.Offset(, 4) = Q(0) - Dic1(Dn.Value)
                Q(1) = True
            [COLOR="Navy"]End[/COLOR] If
        Dic2(Dn.Value) = Q
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,025
Members
448,939
Latest member
Leon Leenders

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