Microsoft Office Tutorials and References
In Depth Information
VBA Operator Precedence
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
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
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.