+ Reply to Thread
Results 1 to 8 of 8

Extract Dates from String

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-23-2010
    Location
    Staten Island, NY
    MS-Off Ver
    Excel 2003
    Posts
    242

    Re: Extract Dates from String

    Here is what I have so far:

    Sub snb()
    
    Dim j As Integer
    Dim sq As Variant
    Dim stra As Variant
    
        sq = Filter(Split("From JAN-01-2011 To JAN-15-2011"), "-")
     
        If Len(stra(i)) > 16 Then
            For j = 0 To UBound(sq)
                x1 = CDate(sq(j))
            Next
        Else
        
        End If
        
    End Sub
    I need to do 3 things with this code now:

    1) They need to be saved in two separate variables
    2) They need to be in date format
    3) It also needs to work if the sting only has one date in it (like the example I gave)

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Extract Dates from String

    The code I posted was already set up to do those three things:

    Sub extract()
    
        Dim stra(2) As String
        Dim dte1 As Date
        Dim dte2 As Date
        
        stra(0) = "FROM JAN-01-2011 To JAN-15-2011"
        stra(1) = "FROM JAN-01-2010"
        
        For i = 0 To 1
            If Len(stra(i)) > 16 Then
                dte1 = CDate(Right(stra(i), 11))
                dte2 = CDate(Right(Left(stra(0), 16), 11))
            Else
                dte1 = CDate(Right(stra(i), 11))
            End If
        Next i
    
    End Sub
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

+ Reply to Thread

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