Hi,
I am using a code to paste data from another program but when it is imported it changes date format which I have been using the parsedate code below to rectify. The problem that I have now is I am also using the below datevalue code to make the data into date format and allow filters to be used. However when I run the both code and even run it a second time the parse date doesnt work and I end up with mm-dd-yyyy for the first 9 days of the month, can anyone help me with this?
Parse date code;
Function ParseDate(dateString)
Dim phase As Integer
Dim i As Integer
Dim ch, Day, Month, Year
phase = 0
For i = 1 To Len(dateString)
ch = Mid(dateString, i, 1)
If IsNumeric(ch) = True Then
If phase = 0 Then Day = Day * 10 + ch
If phase = 1 Then Month = Month * 10 + ch
If phase = 2 Then Year = Year * 10 + ch
Else
phase = phase + 1
End If
If phase = 3 Then
Exit For
End If
Next i
If Year < 1000 Then Year = Year + 2000
ParseDate = DateSerial(Year, Month, Day)
End Function
Datevalue Code;
Sub date12()
Dim c As Range
Dim d As Range
Dim e As Range
Dim f As Range
Range("A:A,N:N,Q:Q,R:R").Select
Range("R1").Activate
Selection.NumberFormat = "dd/mm/yyyy"
For Each c In Range("A2:A" & Range("A" & Rows.Count).End(3).Row)
c.Value = DateValue(c)
On Error Resume Next
If Not IsNumeric(c) Then c.Value = DateValue(c.Value)
Next c
For Each d In Range("N2:N" & Range("N" & Rows.Count).End(3).Row)
d.Value = DateValue(d.Value)
On Error Resume Next
If Not IsNumeric(d) Then d.Value = DateValue(d.Value)
Next d
For Each e In Range("Q2:Q" & Range("Q" & Rows.Count).End(3).Row)
e.Value = DateValue(e.Value)
On Error Resume Next
If Not IsNumeric(e) Then e.Value = DateValue(e.Value)
Next e
For Each f In Range("R2:R" & Range("R" & Rows.Count).End(3).Row)
f.Value = DateValue(f.Value)
On Error Resume Next
If Not IsNumeric(f) Then f.Value = DateValue(f.Value)
Next f
End Sub
Bookmarks