Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Rounding error???

Hi
I have have wrote the following code to get a value from a cell in one
spreadsheet and put it into another sheet.

The problem is the value is in money ie £25.68 but when the macro puts
the value in the other sheet the value is rounded up or dowm ie £26.00

The following code is a small element of a large macro, but show the
problem if processed.

Dim price As Long
price = ActiveCell.Value
Sheets("Sheet3").Select
Range("I21").Select
ActiveCell.Value = price
End Sub

Any ideas to resolve the problem would be gratfully recieved.

Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 225
Default Rounding error???

You've defined price as being "Long". This is an integral
type, so it will round to an integer when you assign
ActiveCell.Value to it. Try

Dim price as Double

instead.


On 29 Sep, 12:58, oggy wrote:
Hi
I have have wrote the following code to get a value from a cell in one
spreadsheet and put it into another sheet.

The problem is the value is in money ie £25.68 but when the macro puts
the value in the other sheet the value is rounded up or dowm ie £26.00

The following code is a small element of a large macro, but show the
problem if processed.

Dim price As Long
price = ActiveCell.Value
Sheets("Sheet3").Select
Range("I21").Select
ActiveCell.Value = price
End Sub

Any ideas to resolve the problem would be gratfully recieved.

Thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Rounding error???

On Sat, 29 Sep 2007 11:58:44 -0000, oggy wrote:

Hi
I have have wrote the following code to get a value from a cell in one
spreadsheet and put it into another sheet.

The problem is the value is in money ie £25.68 but when the macro puts
the value in the other sheet the value is rounded up or dowm ie £26.00

The following code is a small element of a large macro, but show the
problem if processed.

Dim price As Long
price = ActiveCell.Value
Sheets("Sheet3").Select
Range("I21").Select
ActiveCell.Value = price
End Sub

Any ideas to resolve the problem would be gratfully recieved.

Thanks


Dim price as Long

Long is a long integer value. If you don't want your result to round, Dim
price as Double.

Also, there is a lot of redundancy in your code. There is no need for all the
selects or the last ActiveCell

==========================
Dim price As Double
price = ActiveCell.Value
Sheets("Sheet3").Range("I21").Value = price
=============================

would do the same thing.

Or even:

======================================
Sheets("Sheet3").Range("I21").Value = ActiveCell.Value
==========================================


--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
rounding error pkeegs Excel Discussion (Misc queries) 2 January 13th 10 07:53 AM
rounding error? Steve Excel Discussion (Misc queries) 5 June 1st 08 02:58 PM
rounding error Shawn Excel Programming 1 September 5th 05 12:43 PM
Is this rounding error? Ron Rosenfeld Excel Programming 3 September 13th 04 05:56 PM
Rounding Error Matthew W Excel Programming 5 April 19th 04 10:11 AM


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