Assume that the variable A=5
, variable B=10
, then -
Operators | description | Examples |
---|---|---|
+ |
Adding two operands | A + B = 15 |
- |
Subtract two operands | A - B = -5 |
* |
Multiplying two operands | A * B = 50 |
/ |
Division two operands | B / A = 2 |
% |
The remainder after the modulus operator, integer division | B % A = 0 |
^ |
The exponential operator | B ^ A = 100000 |
Examples
Add a button and try the following example to understand how to use the arithmetic operators in VBA.
Private Sub Constant_demo_Click() Dim a As Integer a = 5 Dim b As Integer b = 10 Dim c As Double c = a + b MsgBox ("Addition Result is " & c) c = a - b MsgBox ("Subtraction Result is " & c) c = a * b MsgBox ("Multiplication Result is " & c) c = b / a MsgBox ("Division Result is " & c) c = b Mod a MsgBox ("Modulus Result is " & c) c = b ^ a MsgBox ("Exponentiation Result is " & c) End Sub
When you click a button or execute the above script, the following will produce similar results.
Addition Result is 15 Subtraction Result is -5 Multiplication Result is 50 Division Result is 2 Modulus Result is 0 Exponentiation Result is 100000