Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Spurious decimals

I have some VBA code that reads data from a worksheet into a variant array.
Some of the data is text, and some is numeric. All the numeric data is read
from cells where it has been rounded to 2 decimals using =ROUND(A1,2) etc.

I then write the contents of the variant (12 rows by 15 columns) back to a
different worksheet with this kind of command:

Worksheets("abc").Range("xyz").value = varData

It works OK, except for the fact that some of the numeric data in the new
worksheet contains spurious decimals. So for instance, varData(1,15) might
equal 1609.30 exactly when I step through the VBA code, but when this number
lands in the new worksheet using the command above, the cell value is now
1609.30004882812.

Can anyone shed any light for me? Am using Excel 2002 on Win XP.

Thanks, SB
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Spurious decimals

You mean like this: (demo'd from the immediate window)

? typename(b!)
Single
b! = 1609.30
? b!
1609.3
? cdbl(b!)
1609.30004882813


so the problem is the coversion from single to double I suspect.

--
Regards,
Tom Ogilvy


"Stephen Brook" wrote in message
...
I have some VBA code that reads data from a worksheet into a variant

array.
Some of the data is text, and some is numeric. All the numeric data is

read
from cells where it has been rounded to 2 decimals using =ROUND(A1,2) etc.

I then write the contents of the variant (12 rows by 15 columns) back to a
different worksheet with this kind of command:

Worksheets("abc").Range("xyz").value = varData

It works OK, except for the fact that some of the numeric data in the new
worksheet contains spurious decimals. So for instance, varData(1,15) might
equal 1609.30 exactly when I step through the VBA code, but when this

number
lands in the new worksheet using the command above, the cell value is now
1609.30004882812.

Can anyone shed any light for me? Am using Excel 2002 on Win XP.

Thanks, SB



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Spurious decimals

Tom,

Yes indeed, that was the problem - thanks. I'd rather stupidly assigned the
cell.value (which I assume Excel stores internally as a Double) to a variable
declared as a Single (not a Double) - so presumably this forced a type
conversion that inadvertently introduced the spurious decimals.

Thanks again,

SB

"Tom Ogilvy" wrote:

You mean like this: (demo'd from the immediate window)

? typename(b!)
Single
b! = 1609.30
? b!
1609.3
? cdbl(b!)
1609.30004882813


so the problem is the coversion from single to double I suspect.

--
Regards,
Tom Ogilvy


"Stephen Brook" wrote in message
...
I have some VBA code that reads data from a worksheet into a variant

array.
Some of the data is text, and some is numeric. All the numeric data is

read
from cells where it has been rounded to 2 decimals using =ROUND(A1,2) etc.

I then write the contents of the variant (12 rows by 15 columns) back to a
different worksheet with this kind of command:

Worksheets("abc").Range("xyz").value = varData

It works OK, except for the fact that some of the numeric data in the new
worksheet contains spurious decimals. So for instance, varData(1,15) might
equal 1609.30 exactly when I step through the VBA code, but when this

number
lands in the new worksheet using the command above, the cell value is now
1609.30004882812.

Can anyone shed any light for me? Am using Excel 2002 on Win XP.

Thanks, SB




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
Count digits before decimals and after decimals Elton Law[_2_] Excel Worksheet Functions 5 April 3rd 23 10:59 AM
Excel: Spurious files created on Save Chris Skrimshire Excel Discussion (Misc queries) 1 October 26th 08 11:39 AM
Spurious files created on Save Chris Skrimshire Excel Discussion (Misc queries) 6 October 22nd 08 10:17 PM
How to eliminate spurious data in a string? Peter Chatterton[_2_] Excel Programming 8 November 11th 04 11:41 PM
Spurious ComboBox change event Tony Adams Excel Programming 2 June 11th 04 02:35 PM


All times are GMT +1. The time now is 10:04 PM.

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"