Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 160
Default MOD giving different results???

When I wrinte this worksheet function in a spreadsheet:

= MOD ( -11993.4 , 29.53058867 )

....I get 25.55 - which is what I want...

....but if I do the same in VBA:

MsgBox -11993.4 Mod 29.53058867

....I get -23 !!!


How come MOD provides different answers, depending on if you're using it
in a spreadsheet or in a VBA-code???

How to make the VBA-code provide the result, that I want?


TIA,

CE

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,045
Default MOD giving different results???

On Mon, 18 Feb 2013 12:01:41 +0100, "Charlotte E." wrote:

How come MOD provides different answers, depending on if you're using it
in a spreadsheet or in a VBA-code???


The "defintions" are diferent

Worksheet: Returns the remainder after number is divided by divisor.
VBA: Used to divide two numbers and return only the remainder BUT firts rounding floating-point numbers to integers.



How to make the VBA-code provide the result, that I want?



Use this equivalent: n - d*INT(n/d)
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 160
Default MOD giving different results???

Thanks :-)

Both for the explanation and the solution...

....got it working :-)


CE


Den 18.02.2013 13:24, Ron Rosenfeld skrev:
On Mon, 18 Feb 2013 12:01:41 +0100, "Charlotte E." wrote:

How come MOD provides different answers, depending on if you're using it
in a spreadsheet or in a VBA-code???


The "defintions" are diferent

Worksheet: Returns the remainder after number is divided by divisor.
VBA: Used to divide two numbers and return only the remainder BUT firts rounding floating-point numbers to integers.



How to make the VBA-code provide the result, that I want?



Use this equivalent: n - d*INT(n/d)

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,045
Default MOD giving different results???

On Mon, 18 Feb 2013 13:58:13 +0100, "Charlotte E." wrote:

Thanks :-)

Both for the explanation and the solution...

...got it working :-)


CE


Glad to help. Thanks for the feedback.
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 147
Default MOD giving different results???

Charlotte E. wrote:
When I wrinte this worksheet function in a spreadsheet:

= MOD ( -11993.4 , 29.53058867 )

...I get 25.55 - which is what I want...

...but if I do the same in VBA:

MsgBox -11993.4 Mod 29.53058867

...I get -23 !!!


How come MOD provides different answers, depending on if you're using it
in a spreadsheet or in a VBA-code???

How to make the VBA-code provide the result, that I want?


because these are two different functions just sharing the same name :)


another example

try trim in excel and trim in vba.

and use " aaa bbb " as example







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
TRUNC zero giving odd results? [email protected] Excel Worksheet Functions 5 August 24th 06 05:26 PM
Very large workbook now giving incorrect results :( [email protected] Excel Discussion (Misc queries) 0 July 17th 06 11:29 PM
Why isn't this macro giving me proper results? Girish Excel Programming 3 September 9th 05 06:56 PM
Equation giving unexpected results Mike K Charts and Charting in Excel 2 January 27th 05 02:58 PM
GetAttr giving unexpected results Janelle Excel Programming 4 November 21st 03 08:58 PM


All times are GMT +1. The time now is 05:32 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"