Author: Oscar Cronquist Article last updated on April 19, 2018

The Mod function returns the remainder after a number is divided by divisor. The Mod function is short for theÂ Modulo operationÂ (link to wikipedia).

MOD(number, divisor)

• Number - The number for which you want to find the remainder.
• Divisor - The number by which you want to divide number.

### What does it mean - findsÂ remainder after a number is divided by divisor?

The remainder is what is left after a division. If you divide 15 with 2 you get 7Â and 1 is left over. 2*7 equals 14 and 15 minusÂ 14Â equalsÂ 1. 1 is the remainder or is left over. MOD(15,2) = 1. Sometimes nothing is left over, like 6 divided by 3 equals 2. The remainder is 0.

MOD(number, divisor)Â can be expressed like this:Â number - divisor*INT(number/divisor)

Example 1,

11 divided by 3 returns 2.

number - divisor*INT(number/divisor)

11-3*INT(11/3)

becomes

11-3*3

becomes

11-9 equalsÂ 2.

Example 2,

Here is a different approach.

14 divided by 5Â is 2Â and 4/5

Take the remainder (4/5) and multiply it with the divisor (5)

5* (4/5) equalsÂ 4. 4 is the answer.

### Practical examples

ApplyÂ a formula every n-thÂ row

The following formula concatenatesÂ cells i column A every third row:

=IF(MOD(ROW(), 3)=0, CONCATENATE(A1, A2, A3), "")

Lets begin with ROW() in cell B3.Â ItÂ is dynamic and changes forÂ each row. It returns the current row number, example in cell B3 ROW() returns 3.

Then the MOD function takes 3 and divides it with 3. MOD(ROW(), 3) returns 0. Â The remainder is zero in cell B3. You can see this part of the formula in column C and the result in column D.

MOD(ROW(),3)=0 is logical expression, it checks if the output from the MOD function is equal to 0. In every third row it is andÂ MOD(ROW(),3)=0 returns TRUE.Â You can see this part of the formula in column EÂ and the result in column F.

The IF function returnsÂ CONCATENATE(A1, A2, A3) if logical expression is TRUE or a blankÂ if logical expression is FALSE.

There are relative cell references in the CONCATENATE function and they change in each cell. DonÂ´t know muchÂ about relative and absolute cell references? Read this:Â Absolute and relative references in excel

=IF(MOD(ROW(), 3)=0, CONCATENATE(A1, A2, A3), "")

Highlight every n-thÂ row

You can use the same technique to highlight every second row with conditional formatting.

Here is how to apply conditional formatting to a cell range. Select aÂ cell range. Go to the "Home" tab on the ribbon. Click Conditional formatting button. Click "New Rule...". Click "Use a formula to determine which cells to format:".

TypeÂ theÂ formula below. Click the "Format" button. Go to tab "Fill". Pick a color. Click OK twice.

Conditional formatting formula: =MOD(ROW(A1),2)=0

If you want to highlight every third row change the formula toÂ =MOD(ROW(A1),3)=0.

Highlight every other group

Example 1,

This conditional formatting rule highlights every other group based on values in column A.

Conditional formatting formula:Â =MOD(SUM(1/COUNTIF(\$A\$2:\$A2,\$A\$2:\$A2)),2)

Column A must be sorted.

Example 2, groups based on values in column A, B and C.

Conditional formatting formula:

=MOD(SUM(1/COUNTIFS(\$A\$2:\$A2, \$A\$2:\$A2, \$B\$2:\$B2, \$B\$2:\$B2, \$C\$2:\$C2, \$C\$2:\$C2)), 2)

Make sure you get the relative and absolute cell references right.

Mod function returns the fractional part

If you use 1 as divisorÂ the mod function returns the fraction of a number.Â numberÂ -Â INT(number/divisor)

You can use this to return only hours from a cell containing date and time, see row 3 in the picture above.

QUOTIENT function returns the INTEGER portion of a division

Quotient functionÂ returns a number withoutÂ theÂ fractional component.

78 / 4 = 19.5

The quotient is 19. Here are more examples, the quotients areÂ in column C.

QUOTIENT(numerator, denominator) uses the same arguments as the MOD function.

C Pearson extracts vectors fromÂ aÂ matrix with the MOD function

Extracting Vectors From A Matrix

### MOD function wonÂ´t work with really large numbers

There seems to be a problem with large numbers and Microsoft knows about it:Â http://support.microsoft.com/kb/119083

The MOD() function returns the #NUM! error if the following condition is true:
('divisor' * 134217728) is less than or equal to 'number'

### Download excel *.xlsx file

You can find all examples in this post in the file below.

Mod function.xlsx

If you want to learn more about array formulas join Advanced excel course.