decreasing from a stable Quantity Macro

shahsavand

Board Regular
Joined
Dec 8, 2014
Messages
74
i wanna decrease my stock with the last time i used my inventory.
for example ID no 1. my need is 200 and my stock is 5000 so my shortage is 5000-200=4800 then you can see we have this Id in another row in which my requirement is 54.here i wanna calculate it like this 4800-54=4746
(stock quantity is stable for each ID)
i need a macro for doing it.please somebody help me.

ProductIDNEEDSTOCKShortage
A12005000
4800
A22002000
A32512-13
A453631
A56254248
B642319
B7213615
B15450004946
B26200194
c656910031
c35412-42
c1426588-177
c26329967

<tbody>
</tbody>
 
Are you sure you are implementing it exactly as described? Here are my results:

Excel 2013
ABCDE
1ProductIDNEEDSTOCKShortage
2A120050004800
3A22002000
4A32512-13
5A453631
6A56254248
7B642319
8B7213615
9B15450004746
10B26200-6
11c1691004677
12c154124623
13c126550004358
14c13250004326

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

Worksheet Formulas
CellFormula
E2=IF(
ISNUMBER(MATCH(B2, B$1:B1, 0)),
LOOKUP(2, 1 / (B$1:B1 = B2), E$1:E1),
D2
)
- C2

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>




Hello again i wanted to expand your formula but i could not figure it out would you please help me?
i wanna calculate my shortage with considering the Replacement ID in other column as table below,
for example in column F i have an ID as replacement for ID 1 which is 12 and it has its own Stock and in column H i have ID 15 which is the second replace for my first ID and also has its own Stock.
i wanna use my first ID stock then use second and then use third one and where ever i face with each one of these three ID calculate from the last remained Stock



ProductIDNEEDSTOCKShortageReplace one StockReplace twoStock
A1200500048001220015250
B154500047461220015250
c16910046771220015250
c1541246231220015250
c1265500043581220015250
c132500043261220015250
A2200200016340
B26200-616340
A32512-13203500
C202153500?3050004010

<colgroup><col span="9"></colgroup><tbody>
</tbody>
 
Upvote 0

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Hi,

Can you please provide a more detailed example, showing expected outputs?
In the existing example its not completely clear what you need the results to look like?
 
Upvote 0
Hi,

Can you please provide a more detailed example, showing expected outputs?
In the existing example its not completely clear what you need the results to look like?



for sure but its hard to explain and my english is not good enough i hope u can find out my purpose
i want to add the amount of first and second replacement to my first stock in order to calculate the whole possibility but the problem is our formula only calculates the stock of first cell from above and when you add some stock for example in cell D3 it doesn't count.

For example
Shortage for ID 1 in model B should be the last remained stock+last remained Stock of Replace One+last remained Stock of replace Two.


MODELIDNEEDSTOCKShortageReplace one StockReplace twoStockTOTAl Stock
A12005000480012200152505450
A1545000474612200152505450
A1695000467712200135005700
B
15450004623122006626667866
C12655000435812200152505450
D1325000432612200152505450

<colgroup><col><col><col><col><col><col><col><col><col><col></colgroup><tbody>
</tbody>

<colgroup><col><col><col><col><col><col><col><col><col><col></colgroup><tbody>
</tbody>
 
Upvote 0
Sorry, I'm not sure I follow this.

Can you apply the original formula replacing the STOCK column with the new Total Stock column?

If not, then perhaps you can provide a more detailed example with changing values in each of the columns and expected outputs and hopefully someone will be able to help.
 
Upvote 0
Sorry, I'm not sure I follow this.

Can you apply the original formula replacing the STOCK column with the new Total Stock column?

If not, then perhaps you can provide a more detailed example with changing values in each of the columns and expected outputs and hopefully someone will be able to help.

total stock=column D+G+I
just consider what if your formula was base on column total stock.(means your stock is not stable anymore)
now how should i calculate the shortage
 
Upvote 0
Code:
=IF(
    ISNUMBER(MATCH(B2, B$1:B1, 0)),
    LOOKUP(2, 1 / (B$1:B1 = B2), E$1:E1),
    J2)
  - C2

I'm not sure what you mean by 'your stock is not stable anymore'.

A more detailed example would help.
 
Upvote 0
Code:
=IF(
    ISNUMBER(MATCH(B2, B$1:B1, 0)),
    LOOKUP(2, 1 / (B$1:B1 = B2), E$1:E1),
    J2)
  - C2

I'm not sure what you mean by 'your stock is not stable anymore'.

A more detailed example would help.



actually i want it this way:
when my shortage in under 0 it should use from stock of the replacements
 
Upvote 0
Code:
=IF(
    ISNUMBER(MATCH(B2, B$1:B1, 0)),
    LOOKUP(2, 1 / (B$1:B1 = B2), E$1:E1),
    J2)
  - C2

I'm not sure what you mean by 'your stock is not stable anymore'.

A more detailed example would help.

would you please see whether it possible to lookup the smallest value if quantity of J2 is in A,D or G column exist.below table might help to understand .if the lookup criteria was not in Column A,D or G it should sum it up from column N
i insert my expected output

CodequantityCodeQuantityCodeQuantityCodeLookupValueTotalquantity
11006500121001must be= -1110
220076001312010must be= 290220
32301201513016must be = 3000330
4360310011150440
570099002-22550
150102903-1660
32001101-20770
880
990
10100
11110
12120
13130
14140
15150
163000

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

Your example isn't completely clear to me (e.g. I don't know why you have -1 as the LookupValue for the Code 1 - shouldn't it be -20?).
If that was just a typo, then perhaps try something like this:

Code:
=IFERROR(
    SMALL(
      CHOOSE(
        {1,2,3},
        IF(A$2:A$8 = J2, B$2:B$8),
        IF(D$2:D$8 = J2, E$2:E$8),
        IF(G$2:G$8 = J2, H$2:H$8)),
      1),
    LOOKUP(J2, N$2:N$17, O$2:O$17))
 
Upvote 0
Hi,

Your example isn't completely clear to me (e.g. I don't know why you have -1 as the LookupValue for the Code 1 - shouldn't it be -20?).
If that was just a typo, then perhaps try something like this:

Code:
=IFERROR(
    SMALL(
      CHOOSE(
        {1,2,3},
        IF(A$2:A$8 = J2, B$2:B$8),
        IF(D$2:D$8 = J2, E$2:E$8),
        IF(G$2:G$8 = J2, H$2:H$8)),
      1),
    LOOKUP(J2, N$2:N$17, O$2:O$17))

You are aweeeeesome dear. Actually this formula helps me to calculate the quantity of replacement which I told you before.
I'm reaaally glad to meet you.
How can I be like you.is there any references for me to study and improve my excel skills?
In this table column B represent the first formula you gave to me.in column E I found a way to calculate the quantity of fist replacement and now with our latest legendary formula I can calculate the rest of.
I will let you know about the result.(I should try it in my office)

Please give me any advice which might be helpful to improve my excel skill.i wanna be like you
 
Upvote 0

Forum statistics

Threads
1,215,217
Messages
6,123,673
Members
449,116
Latest member
HypnoFant

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