+ Reply to Thread
Results 1 to 7 of 7

VBA to convert 1930-1999 year format to year 2000 format

  1. #1
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2010, 2016
    Posts
    1,176

    VBA to convert 1930-1999 year format to year 2000 format

    I have some VBA code that is importing a file from another source. The vendor who created the source file did not take into account how excel treats the 2-digit year. As a result, they are sending me dates that occurs in the year 19xx when it needs to be 20xx. I need to convert any date with a year from 1930-1999 to year 2030-2999. The dates are in column E and I want convert to values. Any assistance is appreciated. Thanks

    Please Login or Register  to view this content.
    Last edited by maacmaac; 11-09-2011 at 04:55 PM.

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: VBA to convert 1930-1999 year format to year 2000 format

    maacmaac,

    Give this a try:
    Please Login or Register  to view this content.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2010, 2016
    Posts
    1,176

    Re: VBA to convert 1930-1999 year format to year 2000 format

    That does work but it doesn't quite solve the issue. I should had explained better: The file contains dates for both 19xx and 20xx. Anything with an original date of 2030 to 2999 was converted from 20xx to 19xx. Any dates with from 2000 to 2029 are correct.

    So there is a mix of dates. I only want to change dates with year 19xx to 20xx. If the date already has 20xx, then do nothing. Thanks.

  4. #4
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: VBA to convert 1930-1999 year format to year 2000 format

    maacmaac,

    Updated code:
    Please Login or Register  to view this content.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: VBA to convert 1930-1999 year format to year 2000 format

    You could change your regional settings to control the interpretation of two-digit years. See http://support.microsoft.com/kb/214391
    Entia non sunt multiplicanda sine necessitate

  6. #6
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2010, 2016
    Posts
    1,176

    Re: VBA to convert 1930-1999 year format to year 2000 format

    I was thinking of doing that but the spreadsheet is going to be distributed to other users and it may not work on their machines.

  7. #7
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2010, 2016
    Posts
    1,176

    Re: VBA to convert 1930-1999 year format to year 2000 format

    Ended up checking to see if year is less than 2000. If it is less than 2000, then perform action, else do nothing. Thanks for all the comments.
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1