Microsoft KB Archive/213446

= XL2000: Changing an Integer to an Excel Serial Number =

Article ID: 213446

Article Last Modified on 11/23/2006

-

APPLIES TO


 * Microsoft Excel 2000 Standard Edition

-



This article was previously published under Q213446





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.



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 the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site:

https://partner.microsoft.com/global/30000104

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.  Start Microsoft Excel and open the workbook with the dates that you want to convert. Start the Visual Basic Editor. (Press ALT+F11) On the Insert menu, click Module.  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  Return to Microsoft Excel (Press ALT+F11). 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.</li> 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.</li></ol>

<div class="references_section">