Decimal places - VBA

ExcelChampion

Well-known Member
Joined
Aug 12, 2005
Messages
976
Something that I've worked around for years, and finally want to fix is, when a formula returns a number that extends out to more than two decimal places, the following code ends up rounding the number to the nearest hundredth, where rng is an array:

Range(rng).value = Range(rng).value

Over the years I've experimented with creating a Variant data type, as in:

Dim myDec as Variant
myDec = Range(rng).value
Range(rng).value=myDec

But to no avail...

The only thing that I know that works is using the Copy/PasteSpecial method, but I don't like commandeering the user's clipboard to do stuff for obvious reasons.

What is the best process for returning the value from a formula and retaining its precision? Anyone try the sub-data type, Decimal?

Thanks.
 
Last edited:

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Thanks, but its still a no-go.

I've tried that before (and I just tried it again to be sure), and though I'm not positive, I think it throws up a 'Type Mismatch' flag because the cell(s) actually contain formulas. I'm trying to convert the formulas to values.

So, using actual code:

Dim myDec as Double
myDec = .Cells(1, lCol + 21).Offset(26, 0).Resize(lRow - 1, 4).Value
.Cells(1, lCol + 21).Offset(26, 0).Resize(lRow - 1, 4).Value = myDec

It errors (Type mismatch) on: myDec = .Cells(1, lCol + 21).Offset(26, 0).Resize(lRow - 1, 4).Value
 
Upvote 0
Try using:
Code:
Range(rng).value2 = Range(rng).value2
 
Upvote 0
You can't pass the values of multiple cells to a variable declared as Double. It has to be declared as Variant to contain an array.
 
Upvote 0

Forum statistics

Threads
1,214,596
Messages
6,120,438
Members
448,966
Latest member
DannyC96

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