## Other operators

Operators play a major role in VBA. Besides the equal sign operator (discussed in the previous section), VBA provides several other operators. Table 7-3 lists these operators, with which you are familiar from your worksheet formulas experience.

Table 7-3 |
VBA's Operators |

Function |
Operator Symbol |

Addition |
+ |

Multiplication |
* |

Division |
/ |

Subtraction - | |

Exponentiation |
A |

String concatenation |
& |

Integer division (the result |
\ |

is always an integer) | |

Modulo arithmetic (returns |
Mod |

the remainder of a division | |

operation) |

The term concatenation is programmer speak for "put together." Thus, if you concatenate strings, you are combining strings to make a new and improved string.

As shown in Table 7-4, VBA also provides a full set of logical operators. Consult the Help system for complete details.

Table 7-4 |
VBA's Logical Operators |

Operator |
What It Does |

Not |
Performs a logical negation on an expression |

And |
Performs a logical conjunction on two expressions |

Or |
Performs a logical disjunction on two expressions |

XoR |
Performs a logical exclusion on two expressions |

Eqv |
Performs a logical equivalence on two expressions |

Imp |
Performs a logical implication on two expressions |

The precedence order for operators in VBA is exactly the same as in Excel formulas. Exponentiation has the highest precedence. Multiplication and division come next, followed by addition and subtraction. You can use parentheses to change the natural precedence order, making whatever's sandwiched in parentheses come before any operator.

### Working with Arrays

Most programming languages support arrays. An array is a group of variables that have a common name; you refer to a specific variable in the array by using the array name and an index number. For example, you may define an array of 12 string variables to hold the names of the months of the year. If you name the array MonthNames, you can refer to the first element of the array as MonthNames(1), the second element as MonthNames(2), and so on.

## Post a comment