Macro to fill cells under certain criteria

nicoenz

New Member
Joined
Jul 21, 2005
Messages
29
Hey guys, I need some help. I've been frying my brain trying to get a formula but all I get is a circular reference. Someone told me to write a macro to do it which I have no clue how to do.

I have the following 6 columns:
1. Column A: Day {Mon..Sun}
2. Column B: Demand [kg]
3. Column C: Initial Level [kg] (initial level of day n = final level of day n-1 except for day 1)
4. Column D: Delivery day {yes/no} (usually Mon..Fri are Delivery day while Sat&Sun are not)
5. Column D: Number of trucks {int}
6. Column E: Final level [kg] (formula: initial level - demand +#truck*truck capacity)

Also 3 constants:
truck capacity = value of cell R2
initial level = value of cell R3
study length = value of cell R4 (number of days for the study)

What I need is a macro that will fill column D: Number of trucks given a certain criteria. If the final level of the day is below 0, then I need a truck to arrive on that day to offload 20 kg so I don't get a stockout. If one truck is not enough, then I need another and so on.

In my rudimentary logic, I tried writing the algorithm below to try to explain it better

Is today is "Delivery Day"
y: Is tomorrow "Delivery Day" [or the next n consecutive days]
| y: Is Final level of today <0
| . y: increase cell in col.D by 1 (bring one truck today)
| . n: go to next day
| n: Is Final level of today or tomorrow <0
| . y: increase cell in col.D by 1 (bring one truck today)
| . n: go to next day
n: go to next day


repeat for: study length [days]


Can you please help me out?

Regards and thanks
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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