How To Use Mod Operator In Excel

Oct 19, 2020 • edited Oct 21, 2020

How To Use Mod Operator In Excel

The Mod operator in Excel VBA gives the remainder of a division.

Place a command button on your worksheet and add the following code line:

MsgBox 7 Mod 2

Result when you click the command button on the sheet:

Excel VBA Mod Operator Result

Explanation: 7 is divided by 2 (3 times) to give a remainder of 1.

Code line:

MsgBox 8 Mod 2

Result:

Excel VBA Mod Operator Result

Explanation: 8 is divided by 2 (exactly 4 times) to give a remainder of 0.

For a practical example of the mod operator, see our example program Prime Number Checker.

#Tutorial#How To#VBA#If Then Statement

How To Use Macro Comments In Excel's Vba

How to Use The Macro Security in Excel