Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

Description of the Value2 property for the Range object in Excel


View products that this article applies to.

Summary

Microsoft Excel includes a Visual Basic for Applications property called Value2. The Value2 property, which you can use for the Range object, is almost identical to the Value property except that the Value2 property does not use the Currency and Date data types. Depending on how a cell is formatted (for example, with date, currency, or other formats), the two properties may return different values for the same cell.

NOTE: The Value2 property is not available in versions of Excel earlier than Excel 97. Therefore, if a cell is formatted with a currency number format or a date number format, the Value property may not return the expected underlying cell value.

↑ Back to the top


More information

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 different results 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:   Feb 3, 97
    					
  3. Click cell A1, and then click Cells on the Format menu. On the Number tab, click Currency in the Category list, and then 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 then click OK.
  6. Start the Visual Basic Editor (press ALT+F11).
  7. On the Insert menu, click Module.
  8. Enter the following code in the Visual Basic module:
    Sub Value_vs_Value2()
    
        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
    
    End Sub
    					
  9. Run the Value_vs_Value2 macro. To do this, click Macros on the Tools menu, click Value_vs_Value2, and then 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 = 1997-02-03
Date returned by Value2 property = 35464
The underlying cell value in cell A1 is 1.23456789. However, the Value property returns 1.2346. This is because Excel stores currency numbers in an integer format that is scaled by 10,000 to produce a fixed-point number with fifteen digits to the left of the decimal and four digits to the right of the decimal. For cells formatted as currency, the Value2 property returns the actual underlying cell value.

The underlying cell value in cell A2 is 35464, which is the serial number for Feb 3, 97. The Value property returns a date formatted with the short date format. For cells formatted as a date, the Value2 property returns the underlying serial number.

↑ Back to the top


References

For more information about using the Value2 property, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type value2 property in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

↑ Back to the top


Keywords: KB213719, kbprogramming, kbhowto, kbdtacode

↑ Back to the top

Article Info
Article ID : 213719
Revision : 8
Created on : 1/24/2007
Published on : 1/24/2007
Exists online : False
Views : 313