Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Junior Member
 
Posts: 3
Question Small Decimal Won't Copy

I already have a workaround, but would like to understand why this was a problem (Excel 2007):

I have VBA code that is supposed to copy a row of numeric values into a corresponding range of cells in another worksheet.

Range("D13:P13").Cells(x).Value = cel.Offset(0, x).Value

I just found, though, that when one of the cells contains .0010, it comes across as .0000.

Both cells have the same number format, so I am nonplussed at this. My workaround, which solved the problem, is:

Range("D13:P13").Cells(x).Value = Val(CStr(cel.Offset(0, x).Value))

Somehow, casting the original value to a string, then back to a numeric value, makes it come out as .0010 as it should.

WHY was it not coming across correctly in the first place?
  #2   Report Post  
Junior Member
 
Posts: 18
Default

Quote:
Originally Posted by LarryAP View Post
I already have a workaround, but would like to understand why this was a problem (Excel 2007):

I have VBA code that is supposed to copy a row of numeric values into a corresponding range of cells in another worksheet.

Range("D13:P13").Cells(x).Value = cel.Offset(0, x).Value

I just found, though, that when one of the cells contains .0010, it comes across as .0000.

Both cells have the same number format, so I am nonplussed at this. My workaround, which solved the problem, is:

Range("D13:P13").Cells(x).Value = Val(CStr(cel.Offset(0, x).Value))

Somehow, casting the original value to a string, then back to a numeric value, makes it come out as .0010 as it should.

WHY was it not coming across correctly in the first place?
Hi,

I have Excel 2007 and cell formatting is general at whole worksheet.
I added some numbers to D11:D15 ( smallest was 0,00000005 ).
Then i selected continuos area, horizontal or vertical containing 5 cells.
After that i ran following vba-code. It worked ok.

All decimals at destination area was just like sourcearea ( D11:D15).
I think that excel make calculations with 15 decimals, always.

Sub TestSmallDecimal()

For x = 1 To 5
Selection.Cells(x).Value = Range("D10").Offset(x, 0).Value
Next x

End Sub

I dont know the reason why Excel works at your worksheet as you said, but
this exsample worked when I tried to reply your situation.

***
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
large file - copy and paste small group CHEL294 Excel Discussion (Misc queries) 2 June 4th 09 09:08 PM
ISERROR,SMALL,INDEX, MATCH, SMALL?? M.A.Tyler Excel Discussion (Misc queries) 1 May 2nd 07 04:08 AM
HOW DO I COPY & PASTE A SMALL INFO FM AN XL TO THE CELL COMMENT RAGHAV Excel Worksheet Functions 0 May 3rd 06 03:17 PM
Office 2000-Small Business, XCEL eror = copy/paste error Ed-BlanksUSA Excel Discussion (Misc queries) 0 February 7th 06 08:49 PM
i have lost the small + that allows mass copy of formulas in excel Brendan Excel Discussion (Misc queries) 1 January 17th 06 03:29 AM


All times are GMT +1. The time now is 03:48 PM.

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"