What is the MOD function?
=MOD(number, divisor)MOD returns the remainder after division. Use it to test odd and even numbers or to mark every nth row.
According to Microsoft, the result has the same sign as the divisor and is calculated as MOD(n, d) = n - d*INT(n/d). So MOD(-3, 2) is 1, not -1.
Beyond odd and even, MOD handles anything that repeats: a three-shift rotation, a marker every n rows, a time span that crosses midnight. The result cycles from 0 up to just below the divisor, which makes it ideal for assigning numbers in a cycle.
Arguments
- number
- The number or cell to divide.
- divisor
- The number to divide by. 0 returns #DIV/0!.
MOD examples
Example 1. Remainder
=MOD(15, 4)15 divided by 4 leaves 3.
Example 2. Odd or even
=IF(MOD(A2, 2)=0, "Even", "Odd")A remainder of 0 after dividing by 2 means even.
Example 3. Example from Microsoft
=MOD(-3, 2)1. The result follows the sign of the divisor (2).
Example 4. Three-shift rotation
=MOD(ROW()-2, 3)+1Entered in row 2 and copied down, it cycles 1, 2, 3, 1, 2, 3…
Row ROW()-2 MOD(…, 3)+1 2 0 1 3 1 2 4 2 3 5 3 1 Example 5. Shift past midnight
=MOD(B2-A2, 1)From 22:00 to 2:00 the next day gives 4:00 instead of a negative time.
Common mistakes
Negative remainders
MOD(-2.5, 4) is 1.5, not -2.5.
Divisor of 0
Returns #DIV/0!.
Remainders of decimals
With decimal numbers, rounding error can leave a remainder that is not quite 0. Scaling to whole numbers first, as in =MOD(A2*10, B2*10)/10, is safer.
FAQ
- How do I get the quotient?
- Use =INT(A2/B2) or QUOTIENT.
- Does it work with decimals?
- Yes. MOD(3.14159, 1) returns the decimal part.