Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Modulus and the Mod function


The Excel formula MOD(436.15,1) returns the value 0.15. However the Mod
function in VBA returns the value 0, as (quoting from online help) "Usually,
the data type of result is a Byte, Byte variant, Integer, Integer variant,
Long, or Variant containing a Long, regardless of whether or not result is a
whole number."

Can any kind soul indicate how I might achieve the result that the Excel
formula gives? I am basically trying to get my code to split 436.15 into two
elements, 436 and 15, so that I can print the two values to a text file
using the appropriate decimal delimiter for any given country.

Thanks in advance for any help.

Mark Woolven


  #2   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Modulus and the Mod function

You could try something like this:

Function GetDecimalPart(RealValue as Double) as Double

Dim IntTemp as Integer

'Because it truncates, IntTemp will now store the Whole
number part of RealValue
IntTemp = RealValue

'Now subtract the whole number part of RealValue from
RealValue, to get the Decimal part...
GetDecimalPart = RealValue - IntTemp

end function

-----Original Message-----

The Excel formula MOD(436.15,1) returns the value 0.15.

However the Mod
function in VBA returns the value 0, as (quoting from

online help) "Usually,
the data type of result is a Byte, Byte variant, Integer,

Integer variant,
Long, or Variant containing a Long, regardless of whether

or not result is a
whole number."

Can any kind soul indicate how I might achieve the result

that the Excel
formula gives? I am basically trying to get my code to

split 436.15 into two
elements, 436 and 15, so that I can print the two values

to a text file
using the appropriate decimal delimiter for any given

country.

Thanks in advance for any help.

Mark Woolven


.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Modulus and the Mod function

One way:

Public Function Frac(ByVal inVal As Variant) As Variant
Select Case VarType(inVal)
Case vbSingle, vbDouble, vbCurrency, _
vbDate, vbInteger, vbLong
Frac = inVal - Fix(inVal)
Case Else
Frac = CVErr(xlErrValue)
End Select
End Function 'Frac()




In article ,
"Mark Woolven" wrote:

The Excel formula MOD(436.15,1) returns the value 0.15. However the Mod
function in VBA returns the value 0, as (quoting from online help) "Usually,
the data type of result is a Byte, Byte variant, Integer, Integer variant,
Long, or Variant containing a Long, regardless of whether or not result is a
whole number."

Can any kind soul indicate how I might achieve the result that the Excel
formula gives? I am basically trying to get my code to split 436.15 into two
elements, 436 and 15, so that I can print the two values to a text file
using the appropriate decimal delimiter for any given country.

Thanks in advance for any help.

Mark Woolven


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
LINKEDRANGE function - a complement to the PULL function (for getting values from a closed workbook) [email protected] Excel Worksheet Functions 0 September 5th 06 03:44 PM
Vezerid Modulus 11 Mich modulus 11 Excel Discussion (Misc queries) 2 January 24th 06 02:36 PM
modulus 11 formula Mich modulus 11 Excel Worksheet Functions 1 January 19th 06 11:19 AM
Emulate Index/Match combo function w/ VBA custom function Spencer Hutton Excel Worksheet Functions 2 May 2nd 05 05:26 PM
User-Defined Function pre-empting Built-in Function? How to undo???? MarWun Excel Programming 1 August 6th 03 09:31 PM


All times are GMT +1. The time now is 08:14 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"