XL: MOD Function and Mod Operator Return Different Values

Last reviewed: February 2, 1998
Article ID: Q141178
The information in this article applies to:
  • Microsoft Excel for Windows, versions 5.0, 5.0c
  • Microsoft Excel for Windows 95, versions 7.0, 7.0a
  • Microsoft Excel 97 for Windows
  • Microsoft Excel for Windows NT, version 5.0
  • Microsoft Excel for the Macintosh, versions 5.0, 5.0a
  • Microsoft Excel for the Power Macintosh, versions 5.0, 5.0a
  • Microsoft Excel 98 Macintosh Edition

SYMPTOMS

In Microsoft Excel, the result returned by the worksheet MOD function may be different from the result returned by the Visual Basic for Applications Mod operator.

CAUSE

This problem occurs if you use a negative divisor with the MOD function. In general, the MOD function returns the remainder after a number is divided by a divisor. The built-in Microsoft Excel function uses the formula

   MOD(n,d)=n-d*INT(n/d)

where n is the number and d is the divisor. If the divisor is a positive number, the results returned by the MOD worksheet function and the Visual Basic for Applications Mod operator are the same. For example, =MOD(17,3) on a worksheet and 17 Mod 3 on a module sheet will return the same value of 2.

The difference between the MOD worksheet function and the Mod operator occurs because of the way Microsoft Excel uses the INT function. The INT function returns the first negative integer less than or equal to the number. For example, =INT(17,-3) will return -6, because 17 divided by -3 is equal to -5.6666667 and the closest integer that is less than or equal to -5.6666667 is -6.

The result of using the INT function is what makes the worksheet MOD function return a different value than the Mod operator. The Mod operator does not use the same formula containing the INT function and, therefore, it returns a different result with a negative divisor.

WORKAROUND

To return the same answer that the Mod operator returns with a negative divisor, enter the following formula into a worksheet instead of using the built-in Microsoft Excel MOD function

   =N-D*QUOTIENT(N,D)

where N is the number and D is the divisor.

NOTE: You must have the Analysis ToolPak installed to use the QUOTIENT function.

For additional information on both the INT and MOD functions, please see the following articles in the Microsoft Knowledge Base:

   ARTICLE-ID: Q119083
   TITLE     : Excel: MOD() Function Returns #NUM! Error Value

   ARTICLE-ID: Q124107
   TITLE     : XL: Can't Specify Number of Digits with Fix() or Int()

STATUS

Microsoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

REFERENCES

For more information about the MOD function or the Mod operator, click the Answer Wizard tab in Microsoft Excel 7.0 Help, type the following text

   MOD

and then double-click the selected text to go to the desired topic.


Additional query words: 5.00 5.00a 5.00c 7.00 7.00a 97 98 XL98 XL97 XL7 XL5
probres ATP tool pack pak
Keywords : xlformula
Version : WINDOWS:5.0,5.0c,7.00,97; MACINTOSH:5.0,5.0a,98
Platform : MACINTOSH WINDOWS
Issue type : kbprb


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 2, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.