1

When I try this Code:

A = 19 Mod 6.7

the Result is 5 but it should be 5.6 Can someone say me, whats going wrong?

2 Answers2

2

Annoyingly, VBA will round the 6.7 to 7 as it doesn't have a floating point modulus function (cf. Java).

Effectively it evaluates 19 Mod CInt(6.7), and CInt uses German Rounding, rather than integer truncation.

If you want to duplicate the behaviour of the MOD function on a worksheet, see VBA equivalent to Excel's mod function

Bathsheba
  • 231,907
  • 34
  • 361
  • 483
2

MOD is an integer function in VBA. It would be better to use:

a - (b * (a / b))
Rob Anthony
  • 1,743
  • 1
  • 13
  • 17