By using expertatexcel.com you agree to our cookie policy, We and our partners operate globally and use cookies, for multiple purposes

expertatexcel.com

 


Algebra vs Programming Assignment Statement

Macros have a similarity to Algebra. If you don't know Algebra, learning Macros will be harder.

x = 3 + 2

We know that

x = 5


7 = x + 2

We know that x = 5

We subtract 2 from both sides of the equation

7 - 2 = x + 2 - 2

and get

5 = x + 0

and since x + 0 = x we can write

5 = x

we can flip it around and get

x = 5

So algebra has the concept of variables and so does computer programming.

In algebra, we "solve" for the variable, but in programming, a variable is memory storage that allows the program to recall a variable's value.

The = in algebra is different from the = in programming.

In algebra it means equality. The values on the left are equal to the values on the right.

In programming, in VBA it means 2 things.
  • Calculate the value to the right of the equal sign (=) and assign it to the variable on the left of the =. This is called an "Assignment Statement"
  • Test for equality. The value on the left of the = is compared the value on the right of the = and if the same a True value results, if not a False value results. Some decision is made on the basis of this.  Note that in many other programming languages the test for equality is a double equal sign ==. (Python, JavaScript )

    The programming statement x = x + 1 is impossible in algebra.

    But it tells Excel to calculate the value on the left and assign it to the variable x.

    So if x is 0 then after the statement is executed it will be 1.

    If we run the statement again x will be 2.

    You can't write

    x + 1 = x

    because this is considered a syntax error and Excel will show a message


    Compile Error:

    Expected sub, function or property

    OK Help






  •