The MOD function
Returns the remainder after division. The result has the same sign as the divisor.
How to use MOD
MOD returns what is left over after a division. Picture 10 chocolates shared among 3 children: each child gets 3, and 1 is left on the table. =MOD(10,3) is that leftover 1.
That sounds small, but it is one of the handiest functions for spotting patterns. If the remainder is 0 when you divide by 2, the number is even: =MOD(A2,2)=0. To pick out every third row, use =MOD(ROW(),3)=0, which is a common formula for coloring rows with a conditional formatting rule. =MOD(A2,7) gives the days left over after whole weeks, and =MOD(A2,1) gives the time part of a date-and-time value. To hand out a list in turns among four people, let MOD divide a running number by 4 and you get 0, 1, 2, 3, 0, 1 and so on.
The first argument is the number and the second is the divisor. The result takes the sign of the divisor, so =MOD(-3,4) gives 1 and not -3, because -3 is -1 times 4 plus 1. The divisor cannot be 0.
If you want the whole-number part of the division instead, use INT: =INT(10/3).
Syntax
MOD(number, divisor)- number
- The number to divide.
- divisor
- The number to divide by.
Examples
=MOD(110,23)| A | B | |
|---|---|---|
| 1 | 1 |
In plain words: The remainder when 110 is divided by 23.
| A | B | |
|---|---|---|
| 1 | 1 |
Common MOD mistakes
MOD returns #DIV/0!
The divisor is 0 or an empty cell. Guard against it with
=IF(B2=0,"",MOD(A2,B2)).The remainder of a negative number comes out positive
MOD gives the result the sign of the divisor, not of the number. If you want the remainder to keep the number's own sign, use
=A2-B2*TRUNC(A2/B2).Every third row starts in the wrong place
=MOD(ROW(),3)=0hits rows 3, 6, 9 and skips the first row. Subtract 1 first, as in=MOD(ROW()-1,3)=0, to hit rows 1, 4, 7.MOD returns #VALUE!
One of the arguments is text that cannot be read as a number, such as "12 pcs". Clean the cell to a plain number, or pull the number out first, for example
=MOD(VALUE(LEFT(A2,2)),5).
Read the guide
Questions
How do I check whether a number is even or odd?
Divide by 2 with MOD: =MOD(A2,2)=0 is TRUE for an even number. =IF(MOD(A2,2)=0,"Even","Odd") writes the word instead.
How do I shade every other row with MOD?
Add a conditional formatting rule with a formula, such as =MOD(ROW(),2)=0 for the even rows, and pick a fill color.
How do I check whether one number divides evenly by another?
=MOD(A2,B2)=0 is TRUE when B2 goes into A2 with nothing left over, for example to flag order quantities that fit full boxes.
How do I get the whole-number part of a division?
Use INT or QUOTIENT instead of MOD. =INT(10/3) returns 3, while =MOD(10,3) returns the remainder 1.