VBA 相当于 Excel 的 mod 函数 [英] VBA equivalent to Excel's mod function

查看:24
本文介绍了VBA 相当于 Excel 的 mod 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有与 excel 的 mod 函数等效的 vba?

Is there a vba equivalent to excel's mod function?

推荐答案

您想要 mod 运算符.

The expression a Mod b is equivalent to the following formula:

a - (b * (a  b))

编辑添加:

您可能需要考虑一些特殊情况,因为 Excel 使用浮点数学(并返回 float),而 VBA 函数返回一个整数.因此,将 mod 与浮点数一起使用可能需要特别注意:

There are some special cases you may have to consider, because Excel is using floating point math (and returns a float), which the VBA function returns an integer. Because of this, using mod with floating-point numbers may require extra attention:

正如@André 在评论中指出的那样,负数可能与您预期的方向相反.他建议的 Fix() 函数解释了 这里 (MSDN).

As @André points out in the comments, negative numbers may round in the opposite direction from what you expect. The Fix() function he suggests is explained here (MSDN).

这篇关于VBA 相当于 Excel 的 mod 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆