XL: Date Inserted by Recorded Macro May Be in Wrong Century

ID: Q182766


The information in this article applies to:
  • Microsoft Excel for Windows, versions 5.0, 5.0c
  • Microsoft Excel for Windows 95, versions 7.0, 7.0a
  • Microsoft Excel for Windows NT, version 5.0
  • Microsoft Excel for the Macintosh, versions 5.0, 5.0a


SYMPTOMS

In the versions of Microsoft Excel listed at the beginning of this article, if you enter a date in a cell while you are recording a Visual Basic for Applications macro, the macro may incorrectly enter the date when you run the macro.

Specifically, the date may be in the wrong century; for example, instead of 1/1/2020, the date appears as 1/1/1920.


CAUSE

This problem occurs because, when you enter a date while recording a macro, the recorded code contains a two-digit year number instead of a four-digit year number. For example, the recorded code is similar to the following:




   ActiveCell.FormulaR1C1 = "1/1/20" 


When you execute this line of code, Excel inserts the date into the cell as the two-digit year number, 20. As a result, the date falls between 1920 and 2019. This behavior occurs regardless of the date you actually entered in the cell while recording the macro.

For more information about how Excel works with two-digit year numbers, please see the following article in the Microsoft Knowledge Base:

Q164406 XL: How Microsoft Excel Works with Two-Digit Year Numbers


WORKAROUND

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 the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp

To work around this problem, modify the recorded code. For example, if the line of code is the following

ActiveCell.FormulaR1C1 = "1/1/20" 

change it to the following:

ActiveCell.FormulaR1C1 = "1/1/2020"   'January 1, 2020 

After you do this, the code inserts the correct date into the active cell when you run the macro.


STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article.


MORE INFORMATION

For more information about how Microsoft products are affected by year 2000 (Y2K) issues, please see the following Microsoft World Wide Web site:

http://www.microsoft.com/year2000/

Additional query words: XL5 XL7 y2k year2000 1919 1920 1929 1930 2019 2020 2029 2030

Keywords : kb2000 xlvbainfo xlformula
Version : MACINTOSH:5.0,5.0a; WINDOWS:5.0,5.0c,7.0,7.0a; winnt:5.0
Platform : MACINTOSH WINDOWS winnt
Issue type : kbbug


Last Reviewed: November 13, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.