VBA Mod, Excel Floor, etc.
On Tue, 29 Jan 2008 09:23:07 -0800, LesHurley
wrote:
In VBA, I want to find the fractional part of a number, say N=123.456. The
VBA version of Mod rounds N to an integer before it functions. The
WorksheetFunction Mod() isn't available in VBA. WorksheetFunction.Floor() is
available but it wont work with a negative N. Can anyone suggest how to do
this for any real N?
This should work, including with negative N:
===================
Function vbMod1(N)
vbMod1 = N - Fix(N)
End Function
===================
Due to rounding issues, you probably will want to Round to a specified number
of decimals.
--ron
|