Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Currency Data Type and automatic cell formatting

All,

Windows XP, Excel 2000

I have noticed that when my VBA code writes a variable (of Currency data
type) out to a worksheet, the cell automatically truncates or rounds it to
two decimal places, even though the currency variable contains a value with
4 decimal places.

This can be duplicated by creating a simple VBA subroutine behind a clean
worksheet (i.e. no formatting at all):

Public Sub TestItOut()

Dim curMyValue as Currency
Dim dblMyValue as Double

curMyValue = 548126789.4482
dblMyValue = 548126789.4482

Range("A1").Value = curMyValue
Range("B1").Value = dblMyValue

End Sub

A1 will contain 548126789.45, and B1 will contain 548126789.4482.

Does anyone know the rule that governs this automatic formatting? Is the
value always truncated? Is it rounded? Is there any way to stop it from
doing this, or control it?

Thanks,
Mark D.



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Currency Data Type and automatic cell formatting

Look at VBA's help for .Value2

Range("A1").Value2 = curMyValue
Range("B1").Value2 = dblMyValue

Currency and dates can be a pain.


Mark Dev wrote:

All,

Windows XP, Excel 2000

I have noticed that when my VBA code writes a variable (of Currency data
type) out to a worksheet, the cell automatically truncates or rounds it to
two decimal places, even though the currency variable contains a value with
4 decimal places.

This can be duplicated by creating a simple VBA subroutine behind a clean
worksheet (i.e. no formatting at all):

Public Sub TestItOut()

Dim curMyValue as Currency
Dim dblMyValue as Double

curMyValue = 548126789.4482
dblMyValue = 548126789.4482

Range("A1").Value = curMyValue
Range("B1").Value = dblMyValue

End Sub

A1 will contain 548126789.45, and B1 will contain 548126789.4482.

Does anyone know the rule that governs this automatic formatting? Is the
value always truncated? Is it rounded? Is there any way to stop it from
doing this, or control it?

Thanks,
Mark D.


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Currency Data Type and automatic cell formatting

Dave,

Thanks for the info. I had no idea there was a "Value2" property.

This allows me to return the number to the worksheet, without any
formatting, and then I can handle the formatting separately.

Thanks,
Mark

"Dave Peterson" wrote in message
...
Look at VBA's help for .Value2

Range("A1").Value2 = curMyValue
Range("B1").Value2 = dblMyValue

Currency and dates can be a pain.


Mark Dev wrote:

All,

Windows XP, Excel 2000

I have noticed that when my VBA code writes a variable (of Currency data
type) out to a worksheet, the cell automatically truncates or rounds it
to
two decimal places, even though the currency variable contains a value
with
4 decimal places.

This can be duplicated by creating a simple VBA subroutine behind a clean
worksheet (i.e. no formatting at all):

Public Sub TestItOut()

Dim curMyValue as Currency
Dim dblMyValue as Double

curMyValue = 548126789.4482
dblMyValue = 548126789.4482

Range("A1").Value = curMyValue
Range("B1").Value = dblMyValue

End Sub

A1 will contain 548126789.45, and B1 will contain 548126789.4482.

Does anyone know the rule that governs this automatic formatting? Is the
value always truncated? Is it rounded? Is there any way to stop it from
doing this, or control it?

Thanks,
Mark D.


--

Dave Peterson



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Currency Data Type and automatic cell formatting

I think it comes as a surprise to everyone when they first notice it. It did to
me, too.

Mark Dev wrote:

Dave,

Thanks for the info. I had no idea there was a "Value2" property.

This allows me to return the number to the worksheet, without any
formatting, and then I can handle the formatting separately.

Thanks,
Mark

"Dave Peterson" wrote in message
...
Look at VBA's help for .Value2

Range("A1").Value2 = curMyValue
Range("B1").Value2 = dblMyValue

Currency and dates can be a pain.


Mark Dev wrote:

All,

Windows XP, Excel 2000

I have noticed that when my VBA code writes a variable (of Currency data
type) out to a worksheet, the cell automatically truncates or rounds it
to
two decimal places, even though the currency variable contains a value
with
4 decimal places.

This can be duplicated by creating a simple VBA subroutine behind a clean
worksheet (i.e. no formatting at all):

Public Sub TestItOut()

Dim curMyValue as Currency
Dim dblMyValue as Double

curMyValue = 548126789.4482
dblMyValue = 548126789.4482

Range("A1").Value = curMyValue
Range("B1").Value = dblMyValue

End Sub

A1 will contain 548126789.45, and B1 will contain 548126789.4482.

Does anyone know the rule that governs this automatic formatting? Is the
value always truncated? Is it rounded? Is there any way to stop it from
doing this, or control it?

Thanks,
Mark D.


--

Dave Peterson


--

Dave Peterson
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
I type in a number in a cell but it wont convert to currency help Out in VA Excel Worksheet Functions 2 May 28th 10 12:04 AM
Formatting currency in cell Noel Excel Discussion (Misc queries) 2 December 5th 08 10:46 PM
automatic formatting of cells to currency in Excel 2007 mikky Excel Worksheet Functions 0 November 29th 06 12:16 PM
Change Cell Value Across whole WorkSheet/ Workbook if cell type is currency Shashi Bhosale Excel Programming 1 October 11th 04 03:20 PM
Determine the type of currency in a cell Anders[_6_] Excel Programming 2 January 11th 04 02:39 PM


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