VB .value=.value

Scott R

Active Member
Joined
Feb 20, 2002
Messages
463
Office Version
  1. 365
Platform
  1. Windows
Thru code I'm trying to copy, paste special as values. Here's what I have:

With vRng
.Formula = [formula put in several columns]
.Value = .Value
End With

It's working but is truncating values.
The formula evaluates to 0.013 but gets entered into cell as 0.01.
Precision As Displayed is not on.

Any ideas what's happening or suggestions for an easy fix or replacement for the .Value line?
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Perhaps its a formatting issue. Check the format of the cells.

Also, .value=.value is not copying/pasting. Meaning, it does not utilize the clipboard. No copying or pasting is going on. It simply converts the formula to a value.
 
Upvote 0
Scott R,

Try:

Code:
With vRng
  .Formula = [formula put in several columns]
  .Value = .Value
  .NumberFormat = "0.000"
End With


Have a great day,
Stan
 
Upvote 0
No luck so far.

After the .Formula statement, the first cell in vRng evaluates to 0.013 in my Watch expression but the .Value = .Value statement then truncates it to 0.01.
Formatting the cell after the .Value = .Value statement gives 0.010. I want 0.013.
 
Upvote 0
Scott

That code doesn't use PasteSpecial.:eek:
 
Upvote 0
I'm putting formulas into cells, then converting those formulas to values. I'm not using PasteSpecial and don't want to unless I must. The method I'm using works 99% of the time, but it looks like there are instances where coerced formatting or something like it is interfering with the results.
 
Upvote 0
Hi Scott

Try using the range object's Value2 property.

Rich (BB code):
With vRng
          .Formula = [formula put in several columns]
          .Value2 = .Value2
End With

Hope that helps...
 
Upvote 0
Hi Scott

Try using the range object's Value2 property.

Rich (BB code):
With vRng
          .Formula = [formula put in several columns]
          .Value2 = .Value2
End With

Hope that helps...

Thanks, worked great. I'm not familiar with Value2. How is it different and why do you think it mattered in this instance?
 
Upvote 0
Hi Scott,

It makes a difference with date and currency data types.

It is the currency data types that were giving you a headache here. If you have a cell formatted as currency you can use the Value2 property to retrieve the full double value.

The reason is explained here:
http://support.microsoft.com/kb/182812

Microsoft Excel stores currency numbers in an integer format that is scaled by 10,000 to produce a fixed-point number with 15 digits to the left of the decimal and 4 digits to the right of the decimal.

Actually the Value2 property is underused: I believe I remember correctly (it would make sense to me) that for numbers working with it is faster than working with the Value property.
 
Upvote 0

Forum statistics

Threads
1,214,516
Messages
6,119,981
Members
448,934
Latest member
audette89

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