# Automating a Cell Value Calculataion Based on a Range [closed]

Hi,

I'm trying to find a way to do this, but I can't seem to find a sample anywhere yet.
Maybe I just don't know the terms or the function to do it.

Ok, so I have this table

I want the Stock Quantity to be automaticaly updated.

I might have a bad approach to it, but i could only think about making a "Counter" range.

I'm trying to achieve it by doing something like this :

Set a variable lets say x = 0.

Then for each cell in A column which have "orange" value in it, it will look up the value in its representative D cell.

Then it will just sum the value like this x = x + D cell value.

Thus if the D cell value is +3, then x = 0 + (+3) which results in 3.

After that it look for the next cell in A column with "orange" value in it and found one with D cell value of -1.

Then the calculation starts again and update the last one as x = 3 + (-1) which results in 2.

Is it possible to do that ?

What should i do to achieve that ?

Or maybe there's just another simple way around to achieve it that i couldn't think of.

Any kind help would be appreciated, thank you.