Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
XP XP is offline
external usenet poster
 
Posts: 389
Default Return fractional part of values

In an internal VBA calculation, I need to return the fractional part of a
value in a cell.

For example,

5.35 returns 0.35

7.00 returns 0

I thought: dValue = ActiveCell.Value Mod 1

would do it, but this doesn't work...don't know why...

Thanks much in advance for your assistance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default Return fractional part of values

<doesn't work What does that mean?

From Excel Help:

The modulus, or remainder, operator divides number1 by number2 (rounding floating-point numbers to integers)

Try:

Function test(a As Double) As Double
test = a - Int(a)
End Function

Use "Fix" instead of "Int" depending on what you require; see VBA Help

--
Kind regards,

Niek Otten
Microsoft MVP - Excel


"XP" wrote in message ...
| In an internal VBA calculation, I need to return the fractional part of a
| value in a cell.
|
| For example,
|
| 5.35 returns 0.35
|
| 7.00 returns 0
|
| I thought: dValue = ActiveCell.Value Mod 1
|
| would do it, but this doesn't work...don't know why...
|
| Thanks much in advance for your assistance.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 320
Default Return fractional part of values

Fraction = Activecell.Value - INT(Activecell.Value)

"XP" wrote:

In an internal VBA calculation, I need to return the fractional part of a
value in a cell.

For example,

5.35 returns 0.35

7.00 returns 0

I thought: dValue = ActiveCell.Value Mod 1

would do it, but this doesn't work...don't know why...

Thanks much in advance for your assistance.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Return fractional part of values

don't know why...

The operative sentence in XL/VBA Help ("Mod"):

The modulus, or remainder, operator divides number1 by number2
***(rounding floating-point numbers to integers)***

Instead use

With ActiveCell
dValue = .Value - Fix(.Value)
End With

In article ,
XP wrote:

In an internal VBA calculation, I need to return the fractional part of a
value in a cell.

For example,

5.35 returns 0.35

7.00 returns 0

I thought: dValue = ActiveCell.Value Mod 1

would do it, but this doesn't work...don't know why...

Thanks much in advance for your assistance.

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
Formula to return part of a text string luvthavodka Excel Discussion (Misc queries) 9 October 20th 08 05:27 PM
can a function return part of it's result in italics? Jamie Excel Worksheet Functions 1 June 2nd 08 08:46 PM
How do I isolate the Fractional part of a number in Excel VB? Cumulous Excel Programming 2 January 3rd 06 08:58 PM
return left most part of cell Pat Excel Worksheet Functions 5 September 9th 05 04:34 PM
Help needed summing fractional values which have been rounded up madbloke Excel Discussion (Misc queries) 3 July 27th 05 01:58 PM


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