I have some cells with, for an example, this value:
5*A-2*B-4*C
In other cells I would put the values for A, B and C. I would like to make additional cell that would count the value. So, for an example, if in some cells it is written that the value of A is 2, value of B is 3 and value of C is 1, I would like an additional cell that would calculate and put the value 0 (that’s the result of 5*2-2*3-4*1). Possible variables are A, B and C, but they don’t have to be contained in every cell (e.g., some cell may be just 5*A-3*C).
Is that possible? Does anyone know how to write that function?
P.S. I can’t split manualy values in different cells because there are hundreds of them.
Thanks.
This can be done with the VBA function EVALUTE
simple example:
eg if your expression is in A2, and the values of A, B, C are in C2:E2
returns the calculated value
You would want to use a ParamArray instead of A, B, C the variable values to allow for an arbitrary number of variables.
A slightly more complete version:
Usage:
Same data as above plus variable names in C1:E1