2-Digit Year

dalameda

New Member
Joined
Jan 27, 2010
Messages
16
after copying data into excel, it brings over a column of dates showing as "01-Feb-10" for example. This date is stored as a 2 year date. I have formulas that are comparing the dates in this coumn with the current date, but of course it doesnt work right when comparing a 2-digit year with a 4-digit year.
does anybody know how i can create a macro that would start in a certain cell (say G16) automatically go down to the last data string showing in that column (which could change) and "convert XX to 20XX."??
<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /><v:shapetype id=_x0000_t75 stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"> <v:stroke joinstyle="miter"></v:stroke><v:formulas><v:f eqn="if lineDrawn pixelLineWidth 0"></v:f><v:f eqn="sum @0 1 0"></v:f><v:f eqn="sum 0 0 @1"></v:f><v:f eqn="prod @2 1 2"></v:f><v:f eqn="prod @3 21600 pixelWidth"></v:f><v:f eqn="prod @3 21600 pixelHeight"></v:f><v:f eqn="sum @0 0 1"></v:f><v:f eqn="prod @6 1 2"></v:f><v:f eqn="prod @7 21600 pixelWidth"></v:f><v:f eqn="sum @8 21600 0"></v:f><v:f eqn="prod @7 21600 pixelHeight"></v:f><v:f eqn="sum @10 21600 0"></v:f></v:formulas><v:path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"></v:path><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:lock aspectratio="t" v:ext="edit"></o:lock></v:shapetype>
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Isn't it just a case of changing the cell formatting or are these text dates. If they are text dates, select them, Data > Text to Columns, click Next twice, tick Date and select DMY then click Finish.
 
Upvote 0
i can easily select the date range manually and click the "error icon" that appears and choose to change it to a 20XX date, but i am creating this for novice users and would like to just attach a macro to a button that would do that for them.
 
Upvote 0
Are they text or are they dates?

In a spare cell enter

=ISNUMBER(G16)

What does it return?
 
Upvote 0
and no it is not a date stored as text, it is a date but in the format it is in, Excel doesnt know if it is "1910" or "2010"
 
Upvote 0
So they are text dates :)

Try

Code:
Sub ChDates()
Dim LR As Long, i As Long
LR = Range("G" & Rows.Count).End(xlUp).Row
For i = 16 To LR
    With Range("G" & i)
        .NumberFormat = "dd/mm/yyyy"
        .Value = DateValue(.Value)
    End With
Next i
End Sub
 
Upvote 0
ooops, yes they are text...sorry :)

the code worked...awesome stuff. THANK you VERY much!!!!!!!!!!!!
 
Upvote 0
ok...i tried to paste new data in a different column to test the macro again and I get a "type mismatch" debug error and the line highlighted is ".Value = DateValue(.Value)"
the differences in the columns is in column G (like the original code uses" the data format is "01-Feb-10" (the macro still works for that column). in column N, it the exact same issue except the format of the data that is pasted is "01/29/10" I did test it and it it is stored as text.
i did change both "G"s to be "N".

any suggestions?
 
Upvote 0
Neither could I work it out too. The same issue with "type mismatch" debug error and the line highlighted is ".Value = DateValue(.Value)". Can anybody tell what could be the cause of the problem?
 
Upvote 0

Forum statistics

Threads
1,215,040
Messages
6,122,806
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top