VB .value=.value

Scott R

Active Member
Joined
Feb 20, 2002
Messages
449
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

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

ExcelChampion

Well-known Member
Joined
Aug 12, 2005
Messages
976
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
Joined
Jul 30, 2006
Messages
3,656
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

Scott R

Active Member
Joined
Feb 20, 2002
Messages
449
Office Version
  1. 365
Platform
  1. Windows
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

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,358
Office Version
  1. 365
Platform
  1. Windows
Scott

That code doesn't use PasteSpecial.:eek:
 
Upvote 0

Scott R

Active Member
Joined
Feb 20, 2002
Messages
449
Office Version
  1. 365
Platform
  1. Windows
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

Colin Legg

MrExcel MVP
Joined
Feb 28, 2008
Messages
3,497
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
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

Scott R

Active Member
Joined
Feb 20, 2002
Messages
449
Office Version
  1. 365
Platform
  1. Windows
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

Colin Legg

MrExcel MVP
Joined
Feb 28, 2008
Messages
3,497
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
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,191,216
Messages
5,985,319
Members
439,957
Latest member
khaled shafy

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
Top