ilk try shortly. appreciate the effortDid you try both macros ? What happened ? If it didn't work give an example of a couple that didn't work.
Did you try both macros ? What happened ? If it didn't work give an example of a couple that didn't work.
On the one hand you say the date is in the format mm/dd/yy but you then provided a file with all the dates being Text (not dates) and in the format dd-mmm-yy.
What is your process for getting the data ? What is the earliest step in which the macro could be run and can you give us a file with the dates at that point ?
Based on your sample data in Post #8 either of these should work.
The 2nd will work even if some some of the text values have been converted to dates.
Option 1: Text values per sample file dd-mmm-yy
VBA Code:Sub TextDateMake2000() With Range("A2", Cells(Rows.Count, "A").End(xlUp)) .Value = Application.Replace(.Value, 8, 0, "20") End With End Sub
Option 2: Values per sample file either text or date
VBA Code:Sub DateMake2000() Dim rng As Range Dim arr As Variant Dim dtTemp As Date Dim i As Long Set rng = Range("A2", Cells(Rows.Count, "A").End(xlUp)) arr = rng.Value For i = 1 To UBound(arr) dtTemp = CDate(arr(i, 1)) If Year(dtTemp) < 2000 Then dtTemp = DateSerial(Year(dtTemp) + 100, Month(dtTemp), Day(dtTemp)) arr(i, 1) = dtTemp Next i rng.Value = arr End Sub
You only see that option because your cells are Text and not "real dates" as Excel sees them
@daveyc18 which of the above is it (as it appears to you in the cell)? and is the column still column I and the headers in I1?On the one hand you say the date is in the format mm/dd/yy but you then provided a file with all the dates being Text (not dates) and in the format dd-mmm-yy.
On the one hand you say the date is in the format mm/dd/yy but you then provided a file with all the dates being Text (not dates) and in the format dd-mmm-yy.
What is your process for getting the data ? What is the earliest step in which the macro could be run and can you give us a file with the dates at that point ?
Based on your sample data in Post #8 either of these should work.
The 2nd will work even if some some of the text values have been converted to dates.
Option 1: Text values per sample file dd-mmm-yy
VBA Code:Sub TextDateMake2000() With Range("A2", Cells(Rows.Count, "A").End(xlUp)) .Value = Application.Replace(.Value, 8, 0, "20") End With End Sub
Option 2: Values per sample file either text or date
VBA Code:Sub DateMake2000() Dim rng As Range Dim arr As Variant Dim dtTemp As Date Dim i As Long Set rng = Range("A2", Cells(Rows.Count, "A").End(xlUp)) arr = rng.Value For i = 1 To UBound(arr) dtTemp = CDate(arr(i, 1)) If Year(dtTemp) < 2000 Then dtTemp = DateSerial(Year(dtTemp) + 100, Month(dtTemp), Day(dtTemp)) arr(i, 1) = dtTemp Next i rng.Value = arr End Sub
Sub DateMake2000()
Dim rng As Range
Dim arr As Variant
Dim dtTemp As Date
Dim i As Long
Set rng = Range("I2", Cells(Rows.Count, "").End(xlUp))
arr = rng.Value
For i = 1 To UBound(arr)
If IsDate(arr(i, 1)) Then
dtTemp = CDate(arr(i, 1))
If Year(dtTemp) < 2000 Then dtTemp = DateSerial(Year(dtTemp) + 100, Month(dtTemp), Day(dtTemp))
arr(i, 1) = dtTemp
End If
Next i
rng.Value = arr
End Sub
It is extremely important to provide a representative sample of data. I have modified the code below and is should handle the 2 scenarios you have described.
However it still is based around the sample file you provided with a date format of dd-mmm-yy.
You reference to the file containing 00/00/0000 indicates that this may not be the case and you have not responded to repeated questions on showing use the original data format.
Make sure you check a sample of dates in particular one with the day value being <= 12 and one with the day value being >12.
If your initial date format is in fact mm/dd/yy it is likely the code below will reverse the day and month.
VBA Code:Sub DateMake2000() Dim rng As Range Dim arr As Variant Dim dtTemp As Date Dim i As Long Set rng = Range("I2", Cells(Rows.Count, "").End(xlUp)) arr = rng.Value For i = 1 To UBound(arr) If IsDate(arr(i, 1)) Then dtTemp = CDate(arr(i, 1)) If Year(dtTemp) < 2000 Then dtTemp = DateSerial(Year(dtTemp) + 100, Month(dtTemp), Day(dtTemp)) arr(i, 1) = dtTemp End If Next i rng.Value = arr End Sub