Closed Thread
Results 1 to 3 of 3

MOD function problem

  1. #1
    Registered User
    Join Date
    04-26-2007
    Posts
    77

    MOD function problem

    Dear Experts
    Please Login or Register  to view this content.
    The actual value of variable C is 22 but here it displays 2.
    Range("a14") must display 965-22

    What is wrong?

    Please help

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887
    There is actually a bug in the VBA MOD function, in that it converts both values (the number and divisor) into integers prior to determining the MOD result. ( See http://www.bygsoftware.com/issues/modbug.html )

    Instead of your 'c = a Mod 37.324' line, use this instead:
    Please Login or Register  to view this content.
    Last edited by Paul; 06-07-2007 at 02:58 AM.

  3. #3
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628
    Mod works only with integer values, it rounds 37.324 to 37 and give you the same result than '36040 mod 37'.

    You can change your code:
    Please Login or Register  to view this content.
    with:
    Please Login or Register  to view this content.
    Regards,
    Antonio

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1