You are currently offline, waiting for your internet to reconnect

Description of the Value2 property for the Range object

This article was previously published under Q182812
This article has been archived. It is offered "as is" and will no longer be updated.
Microsoft Excel 97 for Windows and Excel 98 for Macintosh include a new Visual Basic for Applications propertycalled Value2. The Value2 property, which you can use for the Range object,is almost identical to the Value property except that the Value2 propertydoes not use the Currency and Date data types. Depending on how a cell isformatted (for example, with date, currency, or other formats), the twoproperties may return different values for the same cell.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. In the following example, the Value and Value2 properties return differentresults for the same cell object. To see the results, follow these steps:

  1. Close and save any open workbooks, and then create a new workbook.
  2. Enter the following in Sheet1:
    A1: 1.23456789
    A2: 2/3/97
  3. Click cell A1 and click cells on the Format menu. Then, on the Number tab, click Currency in the Category list, and click OK.
  4. Click cell A2 and click cells on the Format menu.
  5. Click the Number tab, click Date in the Category list, and click OK.
  6. Start the Visual Basic Editor (press OPTION+F11).
  7. On the Insert menu, click Module.
  8. Enter the following code in the Visual Basic module:
           Sub Value_vs_Value2()         'Creates a cell value formatted as Currency         Range("A1").Formula = "$1.23456789"          'Creates a cell value formatted as a Date         Range("A2").Formula = "2/3/1997"         MsgBox "Currency returned by Value property = " & _            Sheet1.Range("A1").Value         MsgBox "Currency returned by Value2 property = " & _            Sheet1.Range("A1").Value2         MsgBox "Date returned by Value property = " & _            Sheet1.Range("A2").Value         MsgBox "Date returned by Value2 property = " & _            Sheet1.Range("A2").Value2         Range("A3").Value = Range("A1").Value         MsgBox "Currency set by Value property = " & _             Range("A3").Value         Range("A4").Value = Range("A1").Value2         MsgBox "Currency set by Value2 property = " & _            Range("A4").Value2      End Sub						
  9. Run the Value_vs_Value2 macro. To do this, click Macros on the Tools menu. Click Value_vs_Value2 and click Run.
The macro displays the following messages in order:
Currency returned by Value property = 1.2346

Currency returned by Value2 property = 1.23456789

Date returned by Value property = 2/3/97

Date returned by Value2 property = 34002

Currency set by Value property = 1.23

Currency set by Value2 property = 1.23456789

The underlying cell value in cell A1 is 1.23456789, however, the Valueproperty returns 1.2346. This is true because Microsoft Excel storescurrency numbers in an integer format that is scaled by 10,000 to produce afixed-point number with 15 digits to the left of the decimal and 4 digitsto the right of the decimal. For cells formatted as currency, the Value2property returns the actual underlying cell value.

The underlying cell value in cell A2 is the serial number for 2/3/97, whichis 34002. The Value property returns a date formatted with the short dateformat. The Value2 property, for cells formatted as a date, returns theunderlying serial number for the date.

The cell value set in A3 is rounded because the .Value property of A1 returns a number in the currency data type. When you use .Value to apply a number in currency data type, Excel will truncate (not round) it to 2 decimal places. This is also the same as using the following line of code:

Range("A3").Value = cCur(1.23456789)
For more information about using the Value2 property, click the OfficeAssistant, type value2, click Search, andthen click to view the "Value2 Property" topic.

NOTE: If the Assistant is hidden, click the Office Assistant button on theStandard toolbar. If Visual Basic for Applications Help is not installed onyour computer, please see the following article in the Microsoft KnowledgeBase:
120802 Office: How to Add/Remove a Single Office Program or Component

Article ID: 182812 - Last Review: 12/05/2015 08:29:40 - Revision: 4.2

Microsoft Office Excel 2003, Microsoft Excel 2002 Standard Edition, Microsoft Excel 2000 Standard Edition, Microsoft Excel 97 Standard Edition, Microsoft Excel 2004 for Mac, Microsoft Excel X for Mac, Microsoft Excel 2001 for Mac, Microsoft Excel 98 for Macintosh

  • kbnosurvey kbarchive kbhowto kbprogramming KB182812