Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default VBA Mod, Excel Floor, etc.

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?
--
Thanks for your help
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default VBA Mod, Excel Floor, etc.

perhaps...

N-Round(N, 0)
--
HTH...

Jim Thomlinson


"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?
--
Thanks for your help

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default VBA Mod, Excel Floor, etc.

Sub fracpart()
x = Application.InputBox(prompt:="", Type:=1)
x = Abs(x) - Int(Abs(x))
MsgBox (x)
End Sub

will give the fractional part of both positives and negatives as a positive.
--
Gary''s Student - gsnu200766


"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?
--
Thanks for your help

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default VBA Mod, Excel Floor, etc.

This works as the Excel Mod does

Dim N As Double
Dim remain As Double
Dim sign As Boolean

N = 123.456
sign = N < 0
remain = N - Int(N)
MsgBox remain


--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"LesHurley" wrote in message
...
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?
--
Thanks for your help



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default VBA Mod, Excel Floor, etc.

This works fine for my application but , for future reference, it always
returns a positive fraction.
--
Thanks for your help


"Gary''s Student" wrote:

Sub fracpart()
x = Application.InputBox(prompt:="", Type:=1)
x = Abs(x) - Int(Abs(x))
MsgBox (x)
End Sub

will give the fractional part of both positives and negatives as a positive.
--
Gary''s Student - gsnu200766


"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?
--
Thanks for your help



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default VBA Mod, Excel Floor, etc.

-5.4-Round(-5.4,0) = -.4: thats OK but -5.6-Round(-5.6,0) = +.4: Not OK in
general but it would work OK for my particular application since I am testing
if the fractional part is zero.
--
Thanks for your help


"Jim Thomlinson" wrote:

perhaps...

N-Round(N, 0)
--
HTH...

Jim Thomlinson


"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?
--
Thanks for your help

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default VBA Mod, Excel Floor, etc.

Same comment as for Gary's suggestion.
--
Thanks for your help


"Bob Phillips" wrote:

This works as the Excel Mod does

Dim N As Double
Dim remain As Double
Dim sign As Boolean

N = 123.456
sign = N < 0
remain = N - Int(N)
MsgBox remain


--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"LesHurley" wrote in message
...
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?
--
Thanks for your help




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default 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
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default VBA Mod, Excel Floor, etc.

I transcribed it incorrectly, I really meant

Dim N As Double
Dim remain As Double
Dim sign As Boolean

N = -123.456
sign = N < 0
remain = N - Int(N)
MsgBox IIf(sign, -remain, remain)



--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"LesHurley" wrote in message
...
Same comment as for Gary's suggestion.
--
Thanks for your help


"Bob Phillips" wrote:

This works as the Excel Mod does

Dim N As Double
Dim remain As Double
Dim sign As Boolean

N = 123.456
sign = N < 0
remain = N - Int(N)
MsgBox remain


--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my
addy)



"LesHurley" wrote in message
...
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?
--
Thanks for your help






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
Can I draw Floor Plans with Excel or Power Point ? Bud Excel Discussion (Misc queries) 5 April 12th 08 12:53 AM
draw a floor plan to scale in excel MRPEDE Excel Worksheet Functions 5 March 31st 07 03:30 AM
How do I use a block diagram to draw a floor plan in Excel? knightlady00 Excel Discussion (Misc queries) 2 June 18th 06 05:59 PM
How do I link an Excel Data Base to a Visio Floor Plan? DamienStarr Excel Discussion (Misc queries) 1 April 14th 06 03:56 PM
EXCEL: FLOOR/SPACE RATIO CALCULATION ANDREW A Excel Worksheet Functions 1 June 21st 05 02:21 PM


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