Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 201
Default Code not rounding

Excel 2002, WinXP
I have the 3 following lines of code:
MsgBox Round(SumGrossReturn - 1, 3)
DestPut.Offset(, 6) = Round(SumGrossReturn - 1, 3)
DestPut.Offset(, 6).NumberFormat = "0.0%"

The message box returns 0.227
The destination cell gets 22.6999999999%
Why doesn't the destination cell get 22.7% ?
Thanks for your help. Otto


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Code not rounding

Hi Otto,

Because the MsgBox function only displays the rounded number,
it does not change it. This should work...

SumGrossReturn = Round(SumGrossReturn - 1, 3)

Note: Unless you save the original value in another variable,
you lose it.
Another note: Excel 97 VBA does not have a "Round" function.
You have to use: WorksheetFunction.Round(....). So if you expect
your code to run on other machines then...

Regards,
Jim Cone
San Francisco, CA

----- Original Message -----
From: "Otto Moehrbach"
Newsgroups: microsoft.public.excel.programming
Sent: Saturday, July 24, 2004 2:19 PM
Subject: Code not rounding


Excel 2002, WinXP
I have the 3 following lines of code:
MsgBox Round(SumGrossReturn - 1, 3)
DestPut.Offset(, 6) = Round(SumGrossReturn - 1, 3)
DestPut.Offset(, 6).NumberFormat = "0.0%"
The message box returns 0.227
The destination cell gets 22.6999999999%
Why doesn't the destination cell get 22.7% ?
Thanks for your help. Otto

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Code not rounding

Otto,
Please disregard my earlier response, I misread your question.
Regards,
Jim Cone

"Jim Cone" wrote in message ...
Hi Otto,

Because the MsgBox function only displays the rounded number,
it does not change it. This should work...

SumGrossReturn = Round(SumGrossReturn - 1, 3)

Note: Unless you save the original value in another variable,
you lose it.
Another note: Excel 97 VBA does not have a "Round" function.
You have to use: WorksheetFunction.Round(....). So if you expect
your code to run on other machines then...

Regards,
Jim Cone
San Francisco, CA

----- Original Message -----
From: "Otto Moehrbach"
Newsgroups: microsoft.public.excel.programming
Sent: Saturday, July 24, 2004 2:19 PM
Subject: Code not rounding


Excel 2002, WinXP
I have the 3 following lines of code:
MsgBox Round(SumGrossReturn - 1, 3)
DestPut.Offset(, 6) = Round(SumGrossReturn - 1, 3)
DestPut.Offset(, 6).NumberFormat = "0.0%"
The message box returns 0.227
The destination cell gets 22.6999999999%
Why doesn't the destination cell get 22.7% ?
Thanks for your help. Otto

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Code not rounding

On Sat, 24 Jul 2004 17:19:15 -0400, "Otto Moehrbach"
wrote:

Excel 2002, WinXP
I have the 3 following lines of code:
MsgBox Round(SumGrossReturn - 1, 3)
DestPut.Offset(, 6) = Round(SumGrossReturn - 1, 3)
DestPut.Offset(, 6).NumberFormat = "0.0%"

The message box returns 0.227
The destination cell gets 22.6999999999%
Why doesn't the destination cell get 22.7% ?
Thanks for your help. Otto


Perhaps there is something else going on in your code. The following seems to
work just fine for me, with 0.227 showing in the message box, and 22.7%
appearing in G6.

=========================
Sub TestRound()
Dim DestPut As Range
Const SumGrossReturn As Double = 1.226999999

Set DestPut = [A6]

MsgBox Round(SumGrossReturn - 1, 3)

DestPut.Offset(, 6) = Round(SumGrossReturn - 1, 3)
DestPut.Offset(, 6).NumberFormat = "0.0%"

End Sub
========================
--ron
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
split post code (zip code) out of cell that includes full address Concord Excel Discussion (Misc queries) 4 October 15th 09 06:59 PM
ROUNDING FORMULA =ROUND(B12/$B$10,1) ROUNDING TO HIGH SunshineinFt.Myers[_2_] Excel Worksheet Functions 7 March 5th 09 06:41 PM
Drop Down/List w/Code and Definition, only code entered when selec Spiritdancer Excel Worksheet Functions 2 November 2nd 07 03:57 AM
I need a formula with rounding up & rounding down to the nearest . Tony Kay Excel Worksheet Functions 3 May 29th 07 11:13 PM
Rounding questions: (Formula and Code) ? Stuart[_5_] Excel Programming 2 April 8th 04 07:05 PM


All times are GMT +1. The time now is 05:31 AM.

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

About Us

"It's about Microsoft Excel"