SOLVED
Home

2 Digit year when importing

%3CLINGO-SUB%20id%3D%22lingo-sub-65676%22%20slang%3D%22en-US%22%3E2%20Digit%20year%20when%20importing%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-65676%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20importing%20using%20Text%20Import%20Wizard.%20Data%20is%20coming%20from%20older%20legacy%20system%20that%20has%20two%20digit%20years%20(mm%2Fdd%2Fyy).%20Sample%20data%20would%20be%20%2212%2F31%2F49%22.%20Excel%20imports%20this%20as%2012%2F31%2F1949%20when%20it%20should%20be%2012%2F31%2F2049.%3C%2FP%3E%3CP%3EIs%20there%20a%20way%20to%20control%20where%20the%20break%20point%20is%20that%20sets%26nbsp%3Bthe%20four%20digit%20year%20as%2019xx%20vs.%2020xx%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-65676%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-67870%22%20slang%3D%22en-US%22%3ERe%3A%202%20Digit%20year%20when%20importing%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-67870%22%20slang%3D%22en-US%22%3E%3CP%3EIt's%20not%20necessary%20to%20restart%20the%20PC.%20With%20your%20changed%20regional%20settings%20you%20may%20do%20small%20exercise%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E1)%20Enter%20in%20any%20cell%2012%2F31%2F50%20-%20Excel%20displays%2012%2F31%2F2050%3C%2FP%3E%3CP%3E2)%20Get%20External%20Data%20from%20your%20txt%20file%3B%20or%20copy%2Fpaste%20dates%20from%20it%20into%20the%20Excel%20sheet%3B%20or%20enter%20into%20any%20cell%20%3DDATEVALUE(%221%3CSPAN%3E2%2F31%2F50%22)%20-%20for%20all%20above%20the%20result%20will%20be%2012%2F31%2F1950%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EI%20don't%20know%20exactly%20how%20the%20text%20parser%20works%20but%20it%20looks%20like%20it%20uses%20default%20settings%20for%202-digits%20year%20interpretation%20and%20ignores%20calendar%20settings%20in%20Regional%20settings%20block.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EPerhaps%20there%20are%20some%20settings%20in%20the%20registry%2C%20i%20don't%20know.%20But%20in%20any%20case%20all%20such%20decisions%20could%20have%20side%20effect%20on%20another%20applications%20and%2For%20another%20Excel%20files.%20Especially%20if%20you%20share%20your%20files%20with%20someone%20else%20(not%20necessary%20files%20in%20subject).%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EAs%20for%20me%20personally%20i'd%20prefer%20to%20do%20all%20transformations%20within%20the%20file%20i%20work%20with%2C%20not%20changing%20the%20environment.%20That%20could%20be%20more%20time%20consuming%2C%20but%20usually%20is%20more%20reliable.%20For%20this%20particular%20case%20i'd%20use%20helper%20columns%20like%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CPRE%3E%3DIF(%5Bparsed%20cell%5D%20%26lt%3B%3D%2036525%2C%20%5Bparsed%20cell%5D%2B36525%2C%20%5Bparsed%20cell%5D)%3C%2FPRE%3E%3CP%3Ewhich%20returns%20all%20days%20within%2021st%20century%2C%20and%20after%20that%20work%20with%20it.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnyway%2C%20Excel%20always%20suggests%20few%20ways%20to%20achieve%20the%20same%20result%2C%20which%20one%20to%20choose%20depends%20on%20your%20goals%20and%20personal%20preferences.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E-%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-67811%22%20slang%3D%22en-US%22%3ERe%3A%202%20Digit%20year%20when%20importing%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-67811%22%20slang%3D%22en-US%22%3EGood%20method.%20It's%20just%20a%20bummer%20not%20being%20able%20to%20do%20everything%20in%20one%20pass.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-67810%22%20slang%3D%22en-US%22%3ERe%3A%202%20Digit%20year%20when%20importing%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-67810%22%20slang%3D%22en-US%22%3ETrue%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-67809%22%20slang%3D%22en-US%22%3ERe%3A%202%20Digit%20year%20when%20importing%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-67809%22%20slang%3D%22en-US%22%3E%3CP%3EThis%20looks%20impressive.%20I%20wish%20I%20was%20facile%20with%20VBA%20like%20you.%20However%2C%20I've%20found%20over%20the%20years%20I%20spend%20so%20much%20time%20debugging%20without%20the%20deep%20knowledge%20to%20be%20quick%20with%20it%20so%20I%20just%20tend%20to%20avoid%20it%20as%20much%20as%20possible.%20I've%20just%20adapted%20to%20importing%20and%20doing%20Find%2FReplace.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-67807%22%20slang%3D%22en-US%22%3ERe%3A%202%20Digit%20year%20when%20importing%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-67807%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%20for%20the%20suggestion.%20It%20looks%20like%20it%20should%20work%20but%20I%20have%20not%20been%20successful%20using%20it.%20I%20did%20a%20simple%20test%20setting%20the%20date%20range%201976-2075%20and%20put%20%2212%2F31%2F50%22%20in%20a%20notepad%20txt%20file.%20I%20restarted%2C%20then%20attempted%20to%20import%20using%20different%26nbsp%3Bformat%20types.%20Date%20and%20General%20came%20in%20as%2012%2F31%2F1950.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-65917%22%20slang%3D%22en-US%22%3ERe%3A%202%20Digit%20year%20when%20importing%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-65917%22%20slang%3D%22en-US%22%3E%3CP%3EPerhaps%20the%20simplest%20way%20will%20be%20using%20background%20error%20checking%20as%20here%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fsupport.office.com%2Fen-us%2Farticle%2FConvert-dates-stored-as-text-to-dates-8df7663e-98e6-4295-96e4-32a67ec0a680%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fsupport.office.com%2Fen-us%2Farticle%2FConvert-dates-stored-as-text-to-dates-8df7663e-98e6-4295-96e4-32a67ec0a680%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThat's%20important%20in%20your%20Import%20Text%20wizard%20you%20select%20to%20import%20as%20text%2C%20not%20as%20general.%20With%20this%20option%20query%20itself%20won't%20make%20any%20conversions.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAfter%20that%20copy%2Fpaste%20first%20cell%20in%20your%20column%20to%20any%20another%26nbsp%3Bempty%20column.%20You%20shall%20see%20error%20mark%20on%20top%20left%20level%20of%20the%20cell%20where%20data%20pasted.%20Next%20select%20and%20copy%2Fpaste%20the%20rest%20of%20your%20data%20under%20this%20cell%20-%20now%20all%20shall%20be%20marked%20by%20error.%20Select%20all%20cells%20with%20error%2C%20click%20on%20error%20button%20menu%20and%20choose%20proper%20conversion%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20263px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F13942i065D11C63A2D6292%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22DateConversion.JPG%22%20title%3D%22DateConversion.JPG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EHere%20is%20the%20result%20(i'm%20on%20ISO%26nbsp%3Bdate%20format)%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20154px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F13943iA9BC19F4A23E3254%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22DateConversionResult.JPG%22%20title%3D%22DateConversionResult.JPG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EIf%20you%20have%20dates%20both%20before%20and%20after%20millennium%26nbsp%3Byou%20shall%20process%20them%20separately.%20Column%20into%20which%20you%20paste%20shall%20be%20in%20General%20(by%20default)%20or%20Date%20format.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-65702%22%20slang%3D%22en-US%22%3ERe%3A%202%20Digit%20year%20when%20importing%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-65702%22%20slang%3D%22en-US%22%3EJust%20remember%20those%20settings%20affect%20all%20programs%20in%20all%20of%20Windows%20for%20that%20user.%20Unexpected%20results%20in%20other%20applications%20could%20occur.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-65699%22%20slang%3D%22en-US%22%3ERe%3A%202%20Digit%20year%20when%20importing%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-65699%22%20slang%3D%22en-US%22%3E%3CP%3EI%20would%20just%20run%20some%20VBA%20after%20the%20text%20import.%20If%20you%20run%20the%20code%20below%2C%20it%20will%20ask%20you%20for%20the%20TWO%20DIGIT%20transition%20year%20between%201900%2F2000.%20For%20example%2C%20enter%20'50'%20not%20'1950'%3C%2FP%3E%3CPRE%3EOption%20Explicit%0AOption%20Base%200%0AOption%20Compare%20Text%0AOption%20Private%20Module%0A%0ASub%20FixTheDates()%0A''''''''''''''''''''''''''''''''''''''%0A'%20Allows%20changing%20dates%20with%20two-digit%0A'%20years%2C%20using%20the%20transition%20year%20of%0A'%20your%20choice.%20The%20user%20will%20be%20prompted%0A'%20for%20the%20transition%20year.%0A'%20Author%3A%20Chip%20Pearson%2C%20chip%40cpearson.com%0A'%20License%3A%20Explicit%20Public%20Domain%0A''''''''''''''''''''''''''''''''''''''%0A%0A%20%20%20%20Dim%20Year2000%20As%20Long%0A%20%20%20%20Dim%20R%20As%20Range%0A%20%20%20%20Dim%20RR%20As%20Range%0A%20%20%20%20Dim%20Cutoff%20As%20Long%0A%20%20%20%20Dim%20S%20%20As%20String%0A%20%20%20%20%0A%20%20%20%20'%20ensure%20Selection%20is%20not%20null%0A%20%20%20%20If%20Selection%20Is%20Nothing%20Then%0A%20%20%20%20%20%20%20%20MsgBox%20%22The%20'Selection'%20object%20is%20null%20(Nothing).%22%2C%20vbExclamation%20Or%20vbCritical%2C%20%22Null%20Selection%22%0A%20%20%20%20%20%20%20%20Exit%20Sub%0A%20%20%20%20End%20If%0A%20%20%20%20%0A%20%20%20%20'%20ensure%20selection%20is%20an%20Excel.Range%2C%20not%20some%20other%20object%20(e.g.%20a%20Shape)%0A%20%20%20%20If%20Not%20TypeOf%20Selection%20Is%20Excel.Range%20Then%0A%20%20%20%20%20%20%20%20MsgBox%20%22The%20'Selection'%20object%20is%20a%20'%22%20%2B%20TypeName(Selection)%20%2B%20%22'%2C%20not%20a%20range%20of%20cells.%22%20%2B%20vbNewLine%20%2B%20_%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Please%20select%20the%20range%20of%20cells%20and%20run%20this%20procedure%20again.%22%2C%20vbOKOnly%2C%20%22Invalid%20Selection%22%0A%20%20%20%20%20%20%20%20Exit%20Sub%0A%20%20%20%20End%20If%0A%20%0A%20%20%20%20%0A%20%20%20%20'%20let%20the%20user%20choose%20the%20century%20transition.%0A%20%20%20%20Cutoff%20%3D%2030%20'%26lt%3B%26lt%3B%26lt%3B%26lt%3B%26lt%3B%26lt%3B%26lt%3B%26lt%3B%26lt%3B%26lt%3B%26lt%3B%26lt%3B%26lt%3B%26lt%3B%26lt%3B%26lt%3B%20two%20digit%20values%20LESS%20than%20this%20are%20considered%201900%20century.%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20'%20two%20digit%20values%20GREATER%20THAN%20OR%20EQUAL%20TO%20thias%20are%20considered%202000%20century.%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20'%20E.g.%20Cutoff%20%3D%2030%20implies%2026%20means%202026%20and%2036%20means%201936.%0A%20%20%20%20%0A%20%20%20%20S%20%3D%20%22Enter%20the%20two-digit%20year%20at%20which%20the%20century%20cutoff%20occurs.%22%20%2B%20vbNewLine%0A%20%20%20%20S%20%3D%20S%20%2B%20%22Two%20digit%20years%20LESS%20than%20this%20number%20are%20consider%20to%20be%20in%20the%202000%20century.%22%20%2B%20vbNewLine%0A%20%20%20%20S%20%3D%20S%20%2B%20%22Two%20digit%20years%20GREATER%20THAN%20OR%20EQUAL%20TO%20this%20number%20are%20considered%20to%20be%20in%20the%201900%20century.%22%0A%20%20%20%20%0A%20%20%20%20'%20prompt%20the%20user.%20the%20%2250%22%20is%20the%20default%2C%20but%20if%20the%20user%20clicks%20Cancel%2C%0A%20%20%20%20'%20the%20result%20is%200%20and%20we%20get%20out.%0A%20%20%20%20Year2000%20%3D%20Application.InputBox(S%2C%20%22Year%20Cutoff%22%2C%20%2250%22%2C%20Type%3A%3D1)%0A%20%20%20%20If%20Year2000%20%3D%200%20Then%0A%20%20%20%20%20%20%20%20'%20user%20clicked%20cancel%0A%20%20%20%20%20%20%20%20Exit%20Sub%0A%20%20%20%20End%20If%0A%20%20%20%20%0A%20%20%20%20'%20ensure%20valid%20range%0A%20%20%20%20If%20Year2000%20%26lt%3B%3D%200%20Or%20Year2000%20%26gt%3B%3D%2099%20Then%0A%20%20%20%20%20%20%20%20MsgBox%20%22The%20value%20'%22%20%2B%20Str(Year2000)%20%2B%20%22'%20is%20not%20valid.%22%20%2B%20vbNewLine%20%2B%20_%0A%20%20%20%20%20%20%20%20%20%20%20%20%22It%20must%20be%20between%200%20and%2099%20(exclusive).%22%2C%20vbExclamation%20Or%20vbOKOnly%2C%20%22Invalid%20Data%22%0A%20%20%20%20%20%20%20%20Exit%20Sub%0A%20%20%20%20End%20If%0A%20%20%20%20%20%20%20%0A%20%20%20%20'%20set%20our%20range%20of%20cells%0A%20%20%20%20Set%20RR%20%3D%20Selection%0A%20%20%20%20If%20RR.Cells.Count%20%3D%201%20Then%0A%20%20%20%20%20%20%20%20'%20if%20there%20is%20only%20one%20cell%20selected%2C%20the%20user%20likely%20forgot%20to%0A%20%20%20%20%20%20%20%20'%20select%20the%20proper%20range.%20ask%20her.%0A%20%20%20%20%20%20%20%20If%20MsgBox(%22The%20selection%20contains%20only%20on%20cell.%22%20%2B%20vbNewLine%20%2B%20_%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Did%20you%20forget%20to%20select%20the%20range%3F%22%20%2B%20vbNewLine%20%2B%20vbTab%20%2B%20_%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Click%20'Yes'%20to%20continue%20with%20once%20cell%20or%20click%20'No'%22%20%2B%20vbNewLine%20%2B%20vbTab%20%2B%20_%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22to%20exit%20so%20you%20can%20select%20the%20proper%20range.%22%2C%20_%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20vbYesNo%20Or%20vbQuestion%20Or%20vbDefaultButton2)%20%3D%20vbNo%20Then%0A%20%20%20%20%20%20%20%20%20%20%20%20Exit%20Sub%0A%20%20%20%20%20%20%20%20End%20If%0A%20%20%20%20Else%0A%20%20%20%20%20%20%20%20'%20only%20one%20Area%20allowed%0A%20%20%20%20%20%20%20%20If%20RR.Areas.Count%20%26gt%3B%201%20Then%0A%20%20%20%20%20%20%20%20%20%20%20%20MsgBox%20%22You%20may%20only%20run%20this%20procedure%20on%20a%20single%20area%20(a%20rectangular%20range).%22%2C%20vbOKOnly%2C%20%22Invalid%20Selection%22%0A%20%20%20%20%20%20%20%20%20%20%20%20Exit%20Sub%0A%20%20%20%20%20%20%20%20End%20If%0A%20%20%20%20End%20If%0A%20%20%20%20%0A%20%20%20%20On%20Error%20GoTo%20ErrH%3A%0A%20%20%20%20With%20Application%0A%20%20%20%20%20%20%20%20.EnableCancelKey%20%3D%20xlErrorHandler%0A%20%20%20%20%20%20%20%20.EnableEvents%20%3D%20False%0A%20%20%20%20%20%20%20%20.Calculation%20%3D%20xlCalculationManual%0A%20%20%20%20%20%20%20%20.ScreenUpdating%20%3D%20False%0A%20%20%20%20End%20With%0A%20%20%20%20%0A%20%20%20%20'%20restrict%20our%20search%20cells%20to%20numeric%20constants%2C%20ignoring%20formulas%0A%20%20%20%20'%20and%20non-numeric%20data.%0A%20%20%20%20Set%20RR%20%3D%20RR.SpecialCells(xlCellTypeConstants%2C%20xlNumbers)%0A%20%20%20%20%0A%20%20%20%20'%20loop%20through%20the%20cells%20and%20test%20and%20fix%20the%20years%0A%20%20%20%20For%20Each%20R%20In%20RR%0A%20%20%20%20%20%20%20%20If%20Year(DateValue(RR.Text))%20Mod%20100%20%26gt%3B%3D%20Year2000%20Then%0A%20%20%20%20%20%20%20%20%20%20%20%20R.Value%20%3D%20DateSerial(Year(RR)%20Mod%20100%20%2B%20IIf(Year(R)%20Mod%20100%20%26gt%3B%20Cutoff%2C%201900%2C%202000)%2C%20Month(R)%2C%20Day(R))%0A%20%20%20%20%20%20%20%20End%20If%0A%20%20%20%20Next%20R%0A%0AErrH%3A%20'%20We're%20done!%0A%20%20%20%20With%20Application%0A%20%20%20%20%20%20%20%20.EnableEvents%20%3D%20True%0A%20%20%20%20%20%20%20%20.Calculation%20%3D%20xlCalculationAutomatic%0A%20%20%20%20End%20With%0AEnd%20Sub%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-65696%22%20slang%3D%22en-US%22%3ERe%3A%202%20Digit%20year%20when%20importing%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-65696%22%20slang%3D%22en-US%22%3E%3CP%3EChange%20the%20way%20two-digit%20years%20are%20interpreted%3C%2FP%3E%3CDIV%20class%3D%22ocpAlert%22%3E%3CP%20class%3D%22ocpAlertSection%22%3E%3CSTRONG%3EIMPORTANT%3A%3C%2FSTRONG%3E%26nbsp%3BTo%20ensure%20that%20year%20values%20are%20interpreted%20as%20you%20intended%2C%20type%20year%20values%20as%20four%20digits%20(for%20example%2C%202001%2C%20not%2001).%20By%20entering%20four-digit%20years%2C%20Excel%20won't%20interpret%20the%20century%20for%20you.%3C%2FP%3E%3CP%20class%3D%22ocpAlertSection%22%3E%26nbsp%3B%3C%2FP%3E%3C%2FDIV%3E%3CP%3EIf%20you%20enter%20a%20date%20with%20a%20two-digit%20year%20in%20a%20text%20formatted%20cell%20or%20as%20a%20text%20argument%20in%20a%20function%2C%20such%20as%20%3DYEAR(%221%2F1%2F31%22)%2C%20Excel%20interprets%20the%20year%20as%20follows%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CUL%3E%3CLI%3E%3CP%3E%3CSTRONG%3E00%20through%2029%3C%2FSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20is%20interpreted%20as%20the%20years%202000%20through%202029.%20For%20example%2C%20if%20you%20type%20the%20date%20%3CSTRONG%3E5%2F28%2F19%3C%2FSTRONG%3E%2C%20Excel%20assumes%20the%20date%20is%20May%2028%2C%202019.%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3E%3CSTRONG%3E30%20through%2099%3C%2FSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20is%20interpreted%20as%20the%20years%201930%20through%201999.%20For%20example%2C%20if%20you%20type%20the%20date%20%3CSTRONG%3E5%2F28%2F98%3C%2FSTRONG%3E%2C%20Excel%20assumes%20the%20date%20is%20May%2028%2C%201998.%3C%2FP%3E%3C%2FLI%3E%3C%2FUL%3E%3CP%3EIn%20Microsoft%20Windows%2C%20you%20can%20change%20the%20way%20two-digit%20years%20are%20interpreted%20for%20all%20Microsoft%20Windows%20programs%20that%20you%20have%20installed.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3COL%3E%3CLI%3E%3CP%3EClick%20the%20%3CSTRONG%3EStart%3C%2FSTRONG%3E%20button%2C%20and%20then%20click%20%3CSTRONG%3EControl%20Panel%3C%2FSTRONG%3E.%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EDo%20one%20of%20the%20following%3A%3C%2FP%3E%3CUL%3E%3CLI%3E%3CP%3EIn%20Windows%20Vista%2C%20click%20%3CSTRONG%3EClock%2C%20Language%2C%20and%20Region%3C%2FSTRONG%3E.%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EIn%20Windows%20XP%2C%20click%20%3CSTRONG%3EDate%2C%20Time%2C%20Language%2C%20and%20Regional%20Options%3C%2FSTRONG%3E.%3C%2FP%3E%3C%2FLI%3E%3C%2FUL%3E%3C%2FLI%3E%3CLI%3E%3CP%3EClick%20%3CSTRONG%3ERegional%20and%20Language%20Options%3C%2FSTRONG%3E.%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EDo%20one%20of%20the%20following%3A%3C%2FP%3E%3CUL%3E%3CLI%3E%3CP%3EIn%20Windows%20Vista%2C%20in%20the%3CSTRONG%3E%20Regional%20and%20Language%20Options%3C%2FSTRONG%3E%20dialog%20box%2C%20click%20the%20%3CSTRONG%3EFormats%3C%2FSTRONG%3E%20tab.%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EIn%20Windows%20XP%2C%20in%20the%20%3CSTRONG%3ERegional%20and%20Language%20Options%3C%2FSTRONG%3E%20dialog%20box%2C%20click%20the%20%3CSTRONG%3ERegional%20Options%3C%2FSTRONG%3E%20tab.%3C%2FP%3E%3C%2FLI%3E%3C%2FUL%3E%3C%2FLI%3E%3CLI%3E%3CP%3EDo%20one%20of%20the%20following%3A%3C%2FP%3E%3CUL%3E%3CLI%3E%3CP%3EIn%20Windows%20Vista%2C%20click%20%3CSTRONG%3ECustomize%20this%20format%3C%2FSTRONG%3E.%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EIn%20Windows%20XP%2C%20click%20%3CSTRONG%3ECustomize%3C%2FSTRONG%3E.%3C%2FP%3E%3C%2FLI%3E%3C%2FUL%3E%3C%2FLI%3E%3CLI%3E%3CP%3EClick%20the%20%3CSTRONG%3EDate%3C%2FSTRONG%3E%20tab.%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3EIn%20the%20%3CSTRONG%3EWhen%20a%20two-digit%20year%20is%20entered%2C%20interpret%20it%20as%20a%20year%20between%3C%2FSTRONG%3E%20box%2C%20change%20the%20upper%20limit%20for%20the%20century.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAs%20you%20change%20the%20upper-limit%20year%2C%20the%20lower-limit%20year%20automatically%20changes.%3C%2FP%3E%3C%2FLI%3E%3C%2FOL%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20477px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F13900iF8B26050AE70CD41%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Customize%20Format.jpg%22%20title%3D%22Customize%20Format.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESource%3A%20Microsoft%20Office%20Support%20Website%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fsupport.office.com%2Fen-us%2Farticle%2FChange-the-date-system-format-or-two-digit-year-interpretation-aaa2159b-4ae8-4651-8bce-d4707bc9fb9f%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EChange%20the%20date%20system%2C%20format%2C%20or%20two-digit%20year%20interpretation%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-565066%22%20slang%3D%22en-US%22%3ERe%3A%202%20Digit%20year%20when%20importing%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-565066%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F35679%22%20target%3D%22_blank%22%3E%40Haytham%20Amairah%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWindows%207%20Pro%2064%20bit%3C%2FP%3E%3CP%3EA%20software%20rego%20.ini%20file%20is%20importing%20a%20date%20(%202050%20)%20as%201950%2C%20which%20makes%20the%20software%20unregistered.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECan%20you%20think%20of%20where%20in%20the%20setup%20of%20the%20PC%20that%20might%20be%20causing%20this%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHave%20checked%20in%20Customise%20Format%20%E2%80%93%20Calendar%20%26amp%3B%20set%20to%201952%20and%202051%20as%20above%2C%20still%20importing%20as%201950.%3C%2FP%3E%3CP%3EHave%20re-booted%2C%20still%20no%20success.%3C%2FP%3E%3CP%3EAny%20suggestions%3F%3C%2FP%3E%3CP%3ERemember%2C%20this%20is%20not%20an%20excel%20or%20word%20file%2C%20it%20is%20an%20ini%20file%20for%20software%20registration.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-569444%22%20slang%3D%22en-US%22%3ERe%3A%202%20Digit%20year%20when%20importing%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-569444%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESince%20this%20issue%20isn't%20related%20to%20Excel%2C%20I%20suggest%20you%20ask%20another%20community%20such%20as%20this%20%3CA%20href%3D%22https%3A%2F%2Fsuperuser.com%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eone%3C%2FA%3E.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERegards%2C%3C%2FP%3E%3CP%3EHaytham%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F341712%22%20target%3D%22_blank%22%3E%40CQPOS%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
msaintvincent
Occasional Contributor

I am importing using Text Import Wizard. Data is coming from older legacy system that has two digit years (mm/dd/yy). Sample data would be "12/31/49". Excel imports this as 12/31/1949 when it should be 12/31/2049.

Is there a way to control where the break point is that sets the four digit year as 19xx vs. 20xx?

11 Replies
Solution

Change the way two-digit years are interpreted

IMPORTANT: To ensure that year values are interpreted as you intended, type year values as four digits (for example, 2001, not 01). By entering four-digit years, Excel won't interpret the century for you.

 

If you enter a date with a two-digit year in a text formatted cell or as a text argument in a function, such as =YEAR("1/1/31"), Excel interprets the year as follows:

 

  • 00 through 29     is interpreted as the years 2000 through 2029. For example, if you type the date 5/28/19, Excel assumes the date is May 28, 2019.

  • 30 through 99     is interpreted as the years 1930 through 1999. For example, if you type the date 5/28/98, Excel assumes the date is May 28, 1998.

In Microsoft Windows, you can change the way two-digit years are interpreted for all Microsoft Windows programs that you have installed.

 

  1. Click the Start button, and then click Control Panel.

  2. Do one of the following:

    • In Windows Vista, click Clock, Language, and Region.

    • In Windows XP, click Date, Time, Language, and Regional Options.

  3. Click Regional and Language Options.

  4. Do one of the following:

    • In Windows Vista, in the Regional and Language Options dialog box, click the Formats tab.

    • In Windows XP, in the Regional and Language Options dialog box, click the Regional Options tab.

  5. Do one of the following:

    • In Windows Vista, click Customize this format.

    • In Windows XP, click Customize.

  6. Click the Date tab.

  7. In the When a two-digit year is entered, interpret it as a year between box, change the upper limit for the century.

     

    As you change the upper-limit year, the lower-limit year automatically changes.

 

Customize Format.jpg

 

 

Source: Microsoft Office Support Website

Change the date system, format, or two-digit year interpretation

 

I would just run some VBA after the text import. If you run the code below, it will ask you for the TWO DIGIT transition year between 1900/2000. For example, enter '50' not '1950'

Option Explicit
Option Base 0
Option Compare Text
Option Private Module

Sub FixTheDates()
''''''''''''''''''''''''''''''''''''''
' Allows changing dates with two-digit
' years, using the transition year of
' your choice. The user will be prompted
' for the transition year.
' Author: Chip Pearson, chip@cpearson.com
' License: Explicit Public Domain
''''''''''''''''''''''''''''''''''''''

    Dim Year2000 As Long
    Dim R As Range
    Dim RR As Range
    Dim Cutoff As Long
    Dim S  As String
    
    ' ensure Selection is not null
    If Selection Is Nothing Then
        MsgBox "The 'Selection' object is null (Nothing).", vbExclamation Or vbCritical, "Null Selection"
        Exit Sub
    End If
    
    ' ensure selection is an Excel.Range, not some other object (e.g. a Shape)
    If Not TypeOf Selection Is Excel.Range Then
        MsgBox "The 'Selection' object is a '" + TypeName(Selection) + "', not a range of cells." + vbNewLine + _
            "Please select the range of cells and run this procedure again.", vbOKOnly, "Invalid Selection"
        Exit Sub
    End If
 
    
    ' let the user choose the century transition.
    Cutoff = 30 '<<<<<<<<<<<<<<<< two digit values LESS than this are considered 1900 century.
                ' two digit values GREATER THAN OR EQUAL TO thias are considered 2000 century.
                ' E.g. Cutoff = 30 implies 26 means 2026 and 36 means 1936.
    
    S = "Enter the two-digit year at which the century cutoff occurs." + vbNewLine
    S = S + "Two digit years LESS than this number are consider to be in the 2000 century." + vbNewLine
    S = S + "Two digit years GREATER THAN OR EQUAL TO this number are considered to be in the 1900 century."
    
    ' prompt the user. the "50" is the default, but if the user clicks Cancel,
    ' the result is 0 and we get out.
    Year2000 = Application.InputBox(S, "Year Cutoff", "50", Type:=1)
    If Year2000 = 0 Then
        ' user clicked cancel
        Exit Sub
    End If
    
    ' ensure valid range
    If Year2000 <= 0 Or Year2000 >= 99 Then
        MsgBox "The value '" + Str(Year2000) + "' is not valid." + vbNewLine + _
            "It must be between 0 and 99 (exclusive).", vbExclamation Or vbOKOnly, "Invalid Data"
        Exit Sub
    End If
       
    ' set our range of cells
    Set RR = Selection
    If RR.Cells.Count = 1 Then
        ' if there is only one cell selected, the user likely forgot to
        ' select the proper range. ask her.
        If MsgBox("The selection contains only on cell." + vbNewLine + _
                "Did you forget to select the range?" + vbNewLine + vbTab + _
                "Click 'Yes' to continue with once cell or click 'No'" + vbNewLine + vbTab + _
                "to exit so you can select the proper range.", _
                vbYesNo Or vbQuestion Or vbDefaultButton2) = vbNo Then
            Exit Sub
        End If
    Else
        ' only one Area allowed
        If RR.Areas.Count > 1 Then
            MsgBox "You may only run this procedure on a single area (a rectangular range).", vbOKOnly, "Invalid Selection"
            Exit Sub
        End If
    End If
    
    On Error GoTo ErrH:
    With Application
        .EnableCancelKey = xlErrorHandler
        .EnableEvents = False
        .Calculation = xlCalculationManual
        .ScreenUpdating = False
    End With
    
    ' restrict our search cells to numeric constants, ignoring formulas
    ' and non-numeric data.
    Set RR = RR.SpecialCells(xlCellTypeConstants, xlNumbers)
    
    ' loop through the cells and test and fix the years
    For Each R In RR
        If Year(DateValue(RR.Text)) Mod 100 >= Year2000 Then
            R.Value = DateSerial(Year(RR) Mod 100 + IIf(Year(R) Mod 100 > Cutoff, 1900, 2000), Month(R), Day(R))
        End If
    Next R

ErrH: ' We're done!
    With Application
        .EnableEvents = True
        .Calculation = xlCalculationAutomatic
    End With
End Sub
Just remember those settings affect all programs in all of Windows for that user. Unexpected results in other applications could occur.

Perhaps the simplest way will be using background error checking as here https://support.office.com/en-us/article/Convert-dates-stored-as-text-to-dates-8df7663e-98e6-4295-96...

 

That's important in your Import Text wizard you select to import as text, not as general. With this option query itself won't make any conversions.

 

After that copy/paste first cell in your column to any another empty column. You shall see error mark on top left level of the cell where data pasted. Next select and copy/paste the rest of your data under this cell - now all shall be marked by error. Select all cells with error, click on error button menu and choose proper conversion

DateConversion.JPG

Here is the result (i'm on ISO date format)

DateConversionResult.JPG

If you have dates both before and after millennium you shall process them separately. Column into which you paste shall be in General (by default) or Date format.

Thanks for the suggestion. It looks like it should work but I have not been successful using it. I did a simple test setting the date range 1976-2075 and put "12/31/50" in a notepad txt file. I restarted, then attempted to import using different format types. Date and General came in as 12/31/1950.

This looks impressive. I wish I was facile with VBA like you. However, I've found over the years I spend so much time debugging without the deep knowledge to be quick with it so I just tend to avoid it as much as possible. I've just adapted to importing and doing Find/Replace.

True
Good method. It's just a bummer not being able to do everything in one pass.

It's not necessary to restart the PC. With your changed regional settings you may do small exercise:

 

1) Enter in any cell 12/31/50 - Excel displays 12/31/2050

2) Get External Data from your txt file; or copy/paste dates from it into the Excel sheet; or enter into any cell =DATEVALUE("12/31/50") - for all above the result will be 12/31/1950

 

I don't know exactly how the text parser works but it looks like it uses default settings for 2-digits year interpretation and ignores calendar settings in Regional settings block.

 

Perhaps there are some settings in the registry, i don't know. But in any case all such decisions could have side effect on another applications and/or another Excel files. Especially if you share your files with someone else (not necessary files in subject).

 

As for me personally i'd prefer to do all transformations within the file i work with, not changing the environment. That could be more time consuming, but usually is more reliable. For this particular case i'd use helper columns like 

=IF([parsed cell] <= 36525, [parsed cell]+36525, [parsed cell])

which returns all days within 21st century, and after that work with it.

 

Anyway, Excel always suggests few ways to achieve the same result, which one to choose depends on your goals and personal preferences.

 

@Haytham Amairah 

Windows 7 Pro 64 bit

A software rego .ini file is importing a date ( 2050 ) as 1950, which makes the software unregistered.

 

Can you think of where in the setup of the PC that might be causing this?

 

Have checked in Customise Format – Calendar & set to 1952 and 2051 as above, still importing as 1950.

Have re-booted, still no success.

Any suggestions?

Remember, this is not an excel or word file, it is an ini file for software registration.

Hi,

 

Since this issue isn't related to Excel, I suggest you ask another community such as this one.

 

Regards,

Haytham

 

@CQPOS

Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
16 Replies
flashing a white screen while open new tab
cntvertex in Discussions on
11 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
28 Replies
Early preview of Microsoft Edge group policies
Sean Lyndersay in Discussions on
65 Replies