Page 181 - Excel Progamming Weekend Crash Course
P. 181

k540629 ch12.qxd  9/2/03  9:34 AM  Page 156




                156                                                       Saturday Afternoon


               Operators

               Excel provides a number of operators that can be used in formulas: mathematical, conditional,
               and logical, and as you will see, these operators are almost identical to VBA’s own operators.


               Mathematical Operators
               Excel’s mathematical operators are identical to those used in VBA, and they include the
               standard operations of addition (+), subtraction (-), multiplication (*), and division (/), as
               well as the following less common operations:
                   Integer division (\). Performs a division and returns the integer part of the
                   answer.; therefore, 11\3 evaluates to 3.
                   Exponentiation (^). Raises a number to a power. In VBA, 4^2 means four to the
                                  2
                   second power or 4 , and evaluates to 16.
                   Modulus (mod). Performs a division and returns the remainder. For example, 18 mod 5
                   evaluates to 3. Floating-point numbers are rounded to integers when used with mod.

                          Excel does not have an assignment operator. The equal sign is used to indi-
                          cate the start of a formula and also as a comparison operator.
                   Note

               Comparison Operators

               Excel’s comparison operators are identical to VBA’s. These operators perform a comparison
               between two values and return either True or False. For example, you can use these opera-
               tors to determine if numbers in worksheet cells are less than, equal to, or greater than some
               comparison value. They are reviewed here:

                   = Equal to
                   > Greater than
                   < Less than
                   >= Greater than or equal to
                   <= Less than or equal to
                   <> Not equal to



               Logical Operators
               As you learned in Session 5, logical operations are used to work with True/False values.
               Excel does not have logical operators per se, but rather provides the programmer with three
               functions that perform the same tasks as the AND, OR, and NOT operators in VBA:
                   AND(cond1, cond2). Returns True only if cond1 and cond2 are both True; returns
                   False otherwise.
   176   177   178   179   180   181   182   183   184   185   186