Menu

MOD and ABS in Excel: Remainder and Absolute Value

=MOD(A2,B2) returns the remainder after dividing A2 by B2, so =MOD(17,5) is 2. =ABS(A2) returns a number without its sign, so =ABS(B2-C2) is the difference between two values whichever is larger.

Every sheet on this page is live: change a number or a formula and it recalculates.

=MOD(A2,B2) returns the remainder after dividing A2 by B2: =MOD(17,5) is 2, because 5 goes into 17 three times with 2 left over. =ABS(A2) returns the number without its sign, so -42 becomes 42.

Remainder with MOD
C2
ABCD
1NumberDivisorMODTimes it fits
217523
320504
47213
51007214
6-321-1
73-2-1-1
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

Column D shows the other half of the division: QUOTIENT returns the whole number of times the divisor fits, so 17 is 3 times 5 plus 2. Change B2 to 0 and MOD returns #DIV/0!, just as a division by zero does.

MOD syntax

=MOD(number, divisor)

MOD works on decimals too: =MOD(7.5,2) is 1.5, and =MOD(A2,1) returns only the decimal part of a number, such as 0.75 from 3.75. For dates with times, =MOD(A2,1) keeps the time and drops the date.

MOD with negative numbers

Rows 6 and 7 of the sheet above show Excel's rule: the result has the sign of the divisor. =MOD(-3,2) is 1, not -1, and =MOD(3,-2) is -1. Excel calculates MOD as number - divisor * INT(number / divisor), and INT always rounds down.

This is where a spreadsheet and code disagree. In JavaScript, Java, C and C# -3 % 2 is -1; Python's -3 % 2 is 1, like Excel. Google Sheets follows Excel. If you need the sign of the number instead, use =A2-B2*TRUNC(A2/B2).

Even or odd, and every other row

A number is even when MOD(number,2) is 0. That gives an "Even" or "Odd" label, and with ROW it gives a rule that shades every other row. Excel also has ISEVEN and ISODD, which return TRUE or FALSE directly.

Even or odd, and banded rows
C2
ABC
1OrderQtyEven or odd
210014Even
310027Odd
4100310Even
510043Odd
610058Even
710065Odd
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

The conditional formatting rule =MOD(ROW($A2),2)=0 highlights rows 2, 4 and 6, the even row numbers. In Excel this is Home > Conditional Formatting > New Rule > "Use a formula to determine which cells to format", and the shorter =MOD(ROW(),2)=0 works there too. Change the 2 to 3 to shade every third row.

Every nth row: sum every third value

MOD(ROW()-ROW(first),n)=0 is TRUE for the first row of the range and then every nth row after it. Inside SUMPRODUCT it picks every third value out of a column, for example the last month of each quarter.

Sum every third row
E2
ABCDE
1MonthSalesEvery 3rd
2Jan120310
3Feb135
4Mar150
5Apr110
6May125
7Jun160
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

The offsets of the rows are 0 to 5, and =2 keeps offsets 2 and 5: March and June, 150 plus 160. Change =2 to =0 to take January and April instead.

Convert minutes to hours and minutes

MOD and integer division split a total into units: hours and leftover minutes, weeks and leftover days, boxes and loose items.

135 minutes is 2 h 15 min
B2
ABCD
1MinutesHoursMinutes leftLabel
21352152 h 15 min
3590590 h 59 min
4240404 h 0 min
51000164016 h 40 min
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

1000 minutes is 16 hours and 40 minutes. For actual time values (8:30, 17:45) and shifts that cross midnight, =MOD(end-start,1) is the standard formula; see time calculations.

ABS: the difference between two numbers

=ABS(number) drops the minus sign. Its main use is the size of a difference when you do not care which value is larger: how far each forecast was from the actual result, or whether a measurement is within a tolerance.

How far off was each forecast
D2
ABCDE
1WeekForecastActualOff byWithin 10?
2W11201128TRUE
3W29510914FALSE
4W31401382TRUE
5W4809313FALSE
6W51101046TRUE
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

B2-C2 is 8 for W1 and -14 for W2; ABS turns both into a distance. To add up the distances, =SUMPRODUCT(ABS(B2:B6-C2:C6)) works in every version of Excel; here it gives 43, the total of column D. Dividing that by the count gives the mean absolute error.

Try it: MOD and ABS

Eggs into cartons of 12
C2
ABC
1EggsPer cartonLeft over
235012
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

Your turn: In C2, calculate how many eggs are left over after packing the eggs in A2 into full cartons of the size in B2.

Temperature change
D2
ABCD
1CityMorningEveningChange
2Oslo146
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

Your turn: In D2, show how many degrees the temperature changed between B2 and C2, as a positive number whichever reading is higher.

MOD vs QUOTIENT vs INT

You wantFormula17 and 5 give-17 and 5 give
Remainder=MOD(A2,B2)23
Whole times it fits, toward zero=QUOTIENT(A2,B2)3-3
Whole times it fits, rounded down=INT(A2/B2)3-4
Exact division=A2/B23.4-3.4

For positive numbers, QUOTIENT and INT(A2/B2) agree and B2*INT(A2/B2)+MOD(A2,B2) always rebuilds the number. With a negative number only the INT pair adds back up: -4 times 5 plus 3 is -17. Mixing QUOTIENT with MOD on negative numbers is the usual cause of an off-by-one in a schedule or a split.

Frequently Asked Questions

What does MOD do in Excel?

It returns the remainder of a division: =MOD(17,5) is 2, because 5 goes into 17 three times with 2 left over. If the number divides evenly, MOD returns 0.

How do I check if a number is even in Excel?

Use =MOD(A2,2)=0, which is TRUE for even numbers, or =ISEVEN(A2). In a label: =IF(MOD(A2,2)=0,"Even","Odd").

Why does MOD return a positive number for a negative value?

Excel's MOD takes the sign of the divisor: =MOD(-3,2) is 1 and =MOD(3,-2) is -1. Many programming languages give -1 for -3 % 2, so results can differ from code.

How do I get the absolute value in Excel?

Use =ABS(A2): -42 becomes 42 and 42 stays 42. To get the size of a difference without its sign, use =ABS(B2-C2).

How do I sum absolute values in Excel?

Use =SUMPRODUCT(ABS(A2:A7)), which works in every version. In Excel 365 and 2021 =SUM(ABS(A2:A7)) also works.

Coddy programming languages illustration

Learn to code with Coddy

GET STARTED