LocalExcelTool
Get started

Excel MOD function

MOD returns a remainder, which makes it the tool for zebra striping, biweekly rosters and grouping by a fixed cycle. Test for even numbers with MOD(n,2)=0, and for whole hours with MOD(time,1)=0. On negatives the sign follows the divisor, not the dividend.

Math & conditional sums · Available in: Excel 97 and every desktop version since

Syntax

MOD(number, divisor)

What it returns The remainder after division, with the sign of the divisor.

Arguments
numberrequiredThe number to divide.
divisorrequiredThe divisor; the result takes its sign.

Examples

Alternate row shading (conditional formatting)

RowEven?
1
2
3
= MOD(ROW(),2)=0

→ FALSE(第 1 行)、TRUE(第 2 行)

ROW() is the row number, and MOD(row,2)=0 selects even rows. Put that in a conditional formatting formula with a light fill and the sheet gets stripes that survive inserting rows.

Negative remainders are not what you expect

FormulaResult
MOD(-1,3)
MOD(1,-3)
= MOD(-1,3)

→ 2

-1 divided by 3 gives -1 remainder 2, because -1 = 3×(-1) + 2. The sign follows the divisor, so the answer is 2 rather than -1; to get -1 use -1-TRUNC(-1/3)*3.

Common mistakes

  • 1.A zero divisor returns #DIV/0!; check the cycle value is not blank before grouping.
  • 2.Expecting a negative remainder on negative numbers. Following the divisor is the mathematical definition, not a bug.
  • 3.Using MOD on decimals for currency and being surprised by floating-point noise.

How to use it

  1. 1.Click the cell where the result should appear.
  2. 2.Type = then the function name, and press Tab to accept it.
  3. 3.Enter each argument separated by commas; ranges can be dragged with the mouse.
  4. 4.Press Enter. Drag the fill handle down if the same formula applies to more rows.

Frequently asked questions

What is the syntax of MOD?

MOD(number, divisor). What it returns: The remainder after division, with the sign of the divisor.

Which Excel versions support MOD?

Excel 97 and every desktop version since. It is available in every desktop version unless the note above says otherwise.

Why does MOD return an error instead of a value?

A zero divisor returns #DIV/0!; check the cycle value is not blank before grouping.

Related functions

More in this group

Need to get the data in first?

← All Excel formulas