Results 1 to 5 of 5

Parsedate

Threaded View

Burt_100 Parsedate 12-14-2014, 08:25 AM
tim201110 Re: Parsedate 12-14-2014, 10:08 AM
Burt_100 Re: Parsedate 12-14-2014, 12:19 PM
tim201110 Re: Parsedate 12-14-2014, 01:01 PM
Burt_100 Re: Parsedate 12-14-2014, 01:05 PM
  1. #1
    Forum Contributor
    Join Date
    06-17-2010
    Location
    Donemana, NI
    MS-Off Ver
    Excel 2007
    Posts
    386

    Parsedate

    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
    Attached Files Attached Files
    Last edited by Burt_100; 12-14-2014 at 08:29 AM.

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