Microsoft Office Tutorials and References
In Depth Information
TABLE 23.3
VBA Operator Precedence
Exponentiation ^
Multiplication ( * ), division ( / )
Integer division ( \ )
Modulus ( Mod )
Addition ( + ), subtraction ( - )
String concatenation ( & )
Operators that have the same precedence level, such as multiplication and division, are executed in
left-to-right order.
With this information on the precedence rules, you can see that the previous example will evaluate
to 11 because the division will be performed before the addition.
You can use parentheses in an expression to modify the order of execution. Those parts of an
expression enclosed in parentheses are always evaluated first regardless of operator precedence.
20 / (4 + 6)
evaluates to 2 because the parentheses force the addition to be performed before the division. You
can use as many parentheses in an expression as you like as long as they always come in pairs with
each left parenthesis having a matching right parenthesis. Nested parentheses — when one set is
inside another set — execute starting with the innermost set and proceed outward.
Writing Conditional and Loop Statements
An important part of VBA programming is controlling which VBA statements execute and when.
VBA has several tools for this purpose, the two most important being loop statements and
conditional statements.
Using Loop Statements
A loop statement is used to execute a block of VBA statements a certain number of times. There are
three loop statements.
Search JabSto ::

Custom Search