Forum Discussion
Formula/VBA Help
- Nov 23, 2021sherikhan88 Quite some logic but I think I got it. See attached. It's an ugly formula and probably can be optimized. 
Riny_van_Eekelen Thanks again.
I work in retial, we have item codes which needs to be allocated from warehouse to store. Lets say there are few item codes for which stock in warehouse is zero, and one of the store is selling those items alot due to which it runs out of stock, this is my X store and after doing some calculation my system tells that hey sheri, you X store need 47 qty for one week. 
Now, I do not have that item available in warehouse so the option is to fetch the stock from other store.
But other store also need some stock to sell (Minimum Display Quantity-MDQ), here in Column A (which is also the qty required by Store X) we mentioned the MDQ for all the remaining store.
I do not want to fecth anything extra from any store which is not meeting MDQ, and I also do not want to fetch anything extra if the quantity is fulfil. 
in my first example, My MDQ/or Store X requirement is 48.
My store 1 has 47 Qty available, since store 1 stock is less than 48, I do not want to consider this stock for donation.
Now I will check my second store, which has 50 qty, means 2 item extra. So system should take 2 items now the remaining qty required is (48-2=46), then i will see if my third store can fulfil it.
My third store has 92 qty= 92 is greater than 48, =92-48= 44. Store 3 can give 44 and i need 46, so we will take 44 from store 3, remaining quantity is =48-(2+44)= 2, so i will check store 4
My store 4 has 100 qty, and its greater than 48, so it can fulfil my requirement, but now i just need 2 qty. though it can give me 52. So here i want that i will only get 2 qtyamd when I go for next store, no matter how much qty it has it will say 0.
sherikhan88 Quite some logic but I think I got it. See attached. It's an ugly formula and probably can be optimized.
- sherikhan88Nov 23, 2021Copper ContributorRiny_van_Eekelen You're Awesome!!! Not only you understand and solved my issue. But gave your valuable time to me. 
 I kept thinking about the solution for entire day, when i posted it but unable to put the logic into formulas.
 You will be remembered by rest of my generation ! Thank you for all you help.- sherikhan88Nov 23, 2021Copper ContributorI didnt even know, if we can use Max function like this 😞
 Genius- Riny_van_EekelenNov 23, 2021Platinum Contributorsherikhan88 Glad it worked!!