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.

XL2000: Changing an Integer to an Excel Serial Number


View products that this article applies to.

This article was previously published under Q213446

↑ Back to the top


Summary

Many programs export dates as integers. This article contains a sample Microsoft Visual Basic for Applications macro (Sub procedure) that transforms an integer date into a Microsoft Excel serial number.

↑ Back to the top


More information

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals 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 needs.
If you have limited programming experience, you may want to contact a Microsoft Certified Partner or Microsoft Advisory Services. For more information, visit these Microsoft Web sites:

Microsoft Certified Partners - https://partner.microsoft.com/global/30000104

Microsoft Advisory Services - http://support.microsoft.com/gp/advisoryservice

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS This sample macro assumes that the integer date is in the active cell of the worksheet in the form of 980812 (that is, year/month/day). The macro can be adapted for other integer date formats by changing the references in the DATE function.

To run the macro, follow these steps:

CAUTION: This macro overwrites the original date with the new date.
  1. Start Microsoft Excel and open the workbook with the dates that you want to convert.
  2. Start the Visual Basic Editor. (Press ALT+F11)
  3. On the Insert menu, click Module.
  4. Type the following code into the module sheet:
    Sub ConvertInteger()
    
        ' Extract the first two digits.
        yr = Fix(ActiveCell * 0.0001)
    
        ' Extract the second two digits.
        mo = Right(Fix((ActiveCell - (yr * 10000)) * 0.01), 2)
    
        ' Extract the last two digits.
        dy = ActiveCell - (Fix(ActiveCell * 0.01) * 100)
    
        ' Return the result to the original cell in Microsoft Excel date
        ' format.
        ActiveCell.Value = DateSerial(yr, mo, dy)
    
    End Sub
    					
  5. Return to Microsoft Excel (Press ALT+F11).
  6. Click a cell in the worksheet that has a date that needs to be converted, click the Tools menu, point to Macro, and then click Macros.
  7. Click ConvertInteger, and then click Run. If the active cell contains the number 000101, the ConvertInteger macro converts the cell contents to 1/1/00. Excel recognizes the new contents of the cell as a date (00 is automatically recognized as 2000), so you can perform date calculations on the cell.

↑ Back to the top


References

For more information about how to use the sample code in this article, click the article number below to view the article in the Microsoft Knowledge Base:
212536� OFF2000: How to Run Sample Code from Knowledge Base Articles

↑ Back to the top


Keywords: KB213446, kbprogramming, kbinfo, kbhowto, kbdtacode

↑ Back to the top

Article Info
Article ID : 213446
Revision : 8
Created on : 11/23/2006
Published on : 11/23/2006
Exists online : False
Views : 286