Copied Values Truncating

GeneralShamu

Board Regular
Joined
Jul 6, 2007
Messages
127
I am unsure why but when I am copying cells/numerical values from a sheet into an array only 4 decimalp points are being stored.

I define the 2d array as a Variant.

E.g. 36.920465851
is stored as
36.9204 (or possibly 36.9205)

I am unsure if it is being rounded as well as it is quite difficult to find these errors and I have simply noticed it by stumbling upon it.

Any ideas?
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Could you post the code you use to put the values in the array?

Also, how are the cells on the worksheet formatted -- in particular, are the formatted as currency?
 
Upvote 0
Could you post the code you use to put the values in the array?

Also, how are the cells on the worksheet formatted -- in particular, are the formatted as currency?

Formatted as currency; can't post code unfortunately.

I do something like:
x = Cell(...)
ThisWorkbook.Worksheets(...).Cells(...) = x

where x is a String even though the value going into x is a curreny.

[[[I do a lot of string comparisons on the data.]]]
 
Upvote 0
The default property of Range is Value, and the Value property converts values formatted as currency to data type Currency, which is a scaled integer with precision = $0.0001.

So use the Value2 property of the cells.
 
Upvote 0
The default property of Range is Value, and the Value property converts values formatted as currency to data type Currency, which is a scaled integer with precision = $0.0001.

So use the Value2 property of the cells.

Ahh very intriguing.

We have decided to simply truncate the values to 4 decimal places though.

I will definitely keep this in mind going forward.

Thank you shg
 
Upvote 0
You're welcome, but the conversion to Currency rounds, not truncates.
 
Upvote 0
If you're averaging, it's better.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,723
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top