## How to use the MOD function

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.

### Many more examples

### 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.

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

### Articles with the 'MOD' Function

The following 4 articles have formulas that contain the MOD function.

Denisa asks: I have a problem and i cant figure it out, even if i'm seraching for 2 days. I […]

Can someone explain to me why this happens? This example isĀ working. FREQUENCY function returns {2; 1; 1}. 2Ā values (0.1 and […]

The quotient function returns the integer portion of a division. Example, 5/2 = 2.5. The integer is 2. Excel Function […]

Rearrange cells in a cell range to vertically distributed values

The formula in cell B8 uses a named range to calculate the row and column needed to extract the correct […]

### Article with the 'MOD' Function

The following article has a formula that contains the MOD function.

Rearrange cells in a cell range to vertically distributed values

The formula in cell B8 uses a named range to calculate the row and column needed to extract the correct […]

### Functions in 'Math and trigonometry'

The MOD function function is one of many functions in the 'Math and trigonometry' category.

Converts negative numbers to positive numbers, in other words, the ABS function removes the sign. Excel Function Syntax ABS(number) Arguments […]

The ACOS function calculates the arccosine, or inverse cosine, of a number. Formula in cell C3: =ACOS(B3) Excel Function Syntax […]

The ACOSH function calculates the inverse hyperbolic cosine of a number. Formula in cell C3: =ACOSH(B3) Excel Function Syntax ACOSH(number) […]

The ACOT function calculates the inverse cotangent of a number. The returned angle is given in radians from 0 (zero) […]

The ACOTH function calculates the inverse hyperbolic cotangent of a number. Formula in cell C3: =ACOTH(B3) Excel Function Syntax ACOTH(number) […]

How to use the AGGREGATE function

The AGGREGATE function allows you to calculate different specific functions to a list or database. A special AGGREGATE function feature […]

The ASIN function calculatesĀ the arcsine of a number. The angle is in radians and is betweenĀ -pi/2 to pi/2. =ASIN(B3) Excel […]

The ASINH function calculates the inverse hyperbolic sine of a number. =ASINH(B3) Excel Function Syntax ASINH(number) Arguments number Required. Any […]

The ATAN function calculates the arctangent of a number.Ā The returned angle is in radians between -pi/2 to pi/2. =ATAN(B3) Excel […]

The ATAN2 function calculates the arctangent of an angle using specific x- and y-coordinates. The returned angle is in radians […]

The ATANH function calculates theĀ inverse hyperbolic tangent of a number. =ATANH(B3) Excel Function Syntax ATANH(number) Arguments number Required. Must be […]

The BASE function converts a number into a text representation with a given radix (base). Formula in cell C3: =BASE(10, […]

How to use the CEILING function

The CEILING function rounds a number up to its nearest multiple. The number is rounded down if both the number […]

How to use the COMBIN function

The COMBIN function returns the number of combinations for a specific number of elements out of a larger number of […]

How to use the COMBINA function

The COMBINAĀ function calculatesĀ the number of combinations for a given number of elements from a larger group of elements. Formula in […]

The COS function calculates the cosine of an angle. Formula in cell C3: =COS(B3) Excel Function Syntax COS(number) Arguments number […]

The COSH function calculates the hyperbolic cosine of a number. Formula in cell C3: =COSH(B3) Excel Function Syntax COSH(number) Arguments […]

The COT function calculates the cotangent of an angle specified in radians. Formula in cell C3: =COT(B3) Excel Function Syntax […]

The COTH function calculates the hyperbolic cotangent of a hyperbolic angle. The function has been available since Excel 2013. Formula […]

The CSC function calculates theĀ cosecant of an angle (radians). The CSC function returns the same value as 1/SIN(number). Formula in […]

How to use the DECIMAL function

The DECIMAL function converts a text representation of a number in a given base into a decimal number. Formula in […]

How to use the DEGREES function

The DEGREES function calculates degrees from radians. Formula in cell C3: =DEGREES(B3) Excel Function Syntax DEGREES(angle) Arguments angle Required. The […]

The EVEN function rounds a number up to the nearest even whole number. An even number is a number that […]

Returns e raised to the power of a number, e equals 2.71828182845904. Example, e^2 equals 7.389056099 Formula in cell C3: […]

The FACT function returns the factorial of a number. Formula in cell C3: =FACT(B3) Example, 3! = 3*2*1 = 6 […]

How to use the FACTDOUBLE function

The FACTDOUBLE returns the double factorial of a number. Formula in cell C3: =FACTDOUBLE(B3) Excel Function Syntax FACTDOUBLE(number) Arguments number […]

How to use the FLOOR.MATH function

The FLOOR.MATH function rounds a number down to the nearest integer or to the nearest multiple of significance. Formula in […]

How to use the FLOOR.PRECISE function

The FLOOR.PRECISE function rounds a number down to the nearest integer or nearest multiple of significance. Excel Function Syntax FLOOR.PRECISE(number, […]

The GCD calculates the greatestĀ common divisor that divides all given arguments without a remainder. Formula in cell D3: =GCD(B3:B4) Excel […]

Removes the decimal part from positive numbers and returns the whole number (integer) except negative values are rounded down to […]

The LCM function calculates the least common multiple. The least common multiple is the smallest positive integer that is a […]

The LN function calculates the natural logarithm of a number. Natural logarithms are based on the constant e. Formula in […]

The LOG function calculates the logarithm of a number to a specific base. Formula in cell C3: =LOG(10) Excel Function […]

The LOG10 function calculates the logarithm of a number using the base 10. Formula in cell C3: =LOG10(B3) Excel Function […]

How to use the MINVERSE function

The MINVERSE functionĀ calculates the inverse matrix for a given array. This function is useful for solving equations with multiple variables. […]

The MMULT function calculatesĀ the matrix product of two arrays, an array as the same number of rows as array1 and […]

The Mod function returns the remainder after a number is divided by divisor. The Mod function is short for theĀ Modulo […]

How to use the MROUND function

The MROUND function calculates a number rounded to a given multiple. Formula in cell D3: =MROUND(B3,C3) Excel Function Syntax MROUND(number, […]

How to use the MULTINOMIAL function

The MULTINOMIAL function calculates the ratio of the factorial of a sum of values to the product of factorials. Formula […]

The MUNITĀ function calculatesĀ the identity matrix for a given dimension. Array formula in cell B2: =MUNIT(3) The formula above returns an […]

The PI function returns the number pi (Ā¶). Formula in cell B3: =PI() Excel Function Syntax PI() Arguments PI function […]

The POWER function calculates a number raised to a power. Excel Function Syntax POWER(number, power) Arguments number Required. The number […]

How to use the PRODUCT function

The PRODUCT function returns the product of the numbers given in the argument. Formula in cell D3: =PRODUCT(B3:C3) Excel Function […]

How to use the RADIANS function

The RADIANS function converts degrees to radians. Formula in cell C3: =RADIANS(B3) Excel Function Syntax RADIANS(angle) Arguments angle Required. The […]

The RAND function calculates a random real number greater than or equal to 0 and less than 1. The function […]

How to use the RANDBETWEEN function

Returns a random whole number between the numbers you specify. This function is volatile meaning a new random number is […]

How to use the ROUNDDOWN function

The ROUNDDOWN function calculates a number rounded down based on the number of digits to which you want to round […]

How to use the ROUNDUP function

The ROUNDUP function calculates a number rounded up based on the number of digits to which you want to round […]

The SEC function calculates the secant of an angle. Formula in cell E3: =SEC(B3) Excel Function Syntax SEC(number) Arguments number […]

The SECH function calculates the hyperbolic secant of an angle. Formula in cell C3: =SECH(B3) Excel Function Syntax SECH(number) Arguments […]

How to use the SERIESSUM function

The SERIESSUM function calculates the sum of a power series based on the following formula: SERIESSUM(x, n, m, a) = […]

The SIGN function returns the sign of a number. 1 for a positiv number, 0 (zero) for a 0 (zero) […]

The SIN function calculates the sine of an angle. Formula in cell C3: =SIN(B3) Excel Function Syntax SIN(number) Arguments number […]

The SINH function calculates the hyperbolic sine of a number. Formula in cell C3: =SINH(B3) Excel Function Syntax SINH(number) Arguments […]

The SQRT function calculates the positive square root. Formula in cell C3: =SQRT(B3) Excel Function Syntax SQRT(number) Arguments number Required. […]

The SUM function in Excel allows you to add values, the function returns the sum in the cell it is […]

The SUMIF function sums values based on a condition. The condition can be applied to the values being summed or […]

How to use the SUMIFS function

The SUMIFS function in cell D11 adds numbers from column D based on criteria applied to column B and C. […]

How to use the SUMPRODUCT function

The SUMPRODUCT function calculates the product of corresponding values and then returns the sum of each multiplication.

The SUMSQ function calculates the sum of the squares of the arguments. Formula in cell D3: =SUMSQ(B3:B5) 2^2 = 4, […]

How to use the SUMX2MY2 function

The SUMX2MY2function calculates the sum of the difference of squares of corresponding values in two arrays. Formula in cell F3: […]

How to use the SUMX2PY2 function

The SUMX2PY2 function calculates the sum of the sum of squares of corresponding values in two arrays. The sum of […]

How to use the SUMXMY2 function

The SUMXMY2 function calculates the sum of squares of differences of corresponding values in two arrays. Formula in cell F3: […]

The TAN function calculates the tangent of an angle. Formula in cell C3: =TAN(B3) Excel Function Syntax TAN(number) Arguments number […]

The TANH function calculatesĀ the hyperbolic tangent of a number. Formula in cell C3: =TANH(B3) Excel Function Syntax TANH(number) Arguments number […]

The TRUNC function removes the fractional part of the number to an integer. Formula in cell C3: =TRUNC(B3) Excel Function […]

Learn how to use the SUBTOTAL function

The picture above shows row 4 and row 8 hidden, the SUM argument 9 sums all values in C3:C11 whereas […]

The quotient function returns the integer portion of a division. Example, 5/2 = 2.5. The integer is 2. Excel Function […]

### 8 Responses to “How to use the MOD function”

### Leave a Reply

### How to comment

**How to add a formula to your comment**

<code>Insert your formula here.</code>

**Convert less than and larger than signs**

Use html character entities instead of less than and larger than signs.

< becomes < and > becomes >

**How to add VBA code to your comment**

[vb 1="vbnet" language=","]

Put your VBA code here.

[/vb]

**How to add a picture to your comment:**

Upload picture to postimage.org or imgur

Paste image link to your comment.

**Contact Oscar**

You can contact me through this contact form

Hello! Very interesting but the Highlighting every other group Example 1 upon the first column values doesn't actually work as expected. Please try to put i.e. 2 in A7. Any clue why?

It's rounding issue. To fix it just use INT function:

=MOD(INT(SUM(1/COUNTIF($A$2:$A2,$A$2:$A2))),2)

Example 1 would be more representative if we have textual values in column A instead of numbers. In the example as it is we can use simply MOD($A2,2). But with textual values it's much trickier, and the Example 2 is where Oscar's formula realy shows its power.

dopsz,

Very interesting but the Highlighting every other group Example 1 upon the first column values doesn't actually work as expected. Please try to put i.e. 2 in A7. Any clue why?You are right, I forgot to add that column A must be sorted.

Leonid,

Example 1 would be more representative if we have textual values in column A instead of numbers. In the example as it is we can use simply MOD($A2,2). But with textual values it's much trickier, and the Example 2 is where Oscar's formula really shows its power.Yes, bad example. I have changed values in column A.

[…] Mod function […]

[…] You can use the mod function inĀ a conditional formatting formula to highlight ever n-th row: Learn how the MOD function works […]

Hi Oscar,

Thank you for your amazing tricks. Learned a lot from it.

Suppose I need to highlight every other two consective rows:

ACCT Amount

ACCT1 DR 12 Shaded

ACCT2 CR -12 Shaded

ACCT1 DR 14

ACCT2 CR -14

ACCT1 DR 16 Shaded

ACCT2 CR -16 Shaded

ACCT1 DR 20

ACCT2 CR -20

Sanad

=MOD(ROW(A1),4)>=2

Thanks a lot Oscar. That was simple & elegant!