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/30000104Microsoft Advisory Services -
http://support.microsoft.com/gp/advisoryserviceFor 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.
- 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.