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'