+ Reply to Thread
Results 1 to 2 of 2

get date from text & cell based on condition

Hybrid View

  1. #1
    Valued Forum Contributor tek9step's Avatar
    Join Date
    05-27-2009
    Location
    London, England
    MS-Off Ver
    MS 365
    Posts
    389

    get date from text & cell based on condition

    Hi All

    I need help to get date out so far I only have managed to get the number out function from http://www.ozgrid.com/VBA/ExtractNum.htm but what i am looking for is just to get dates with conditions:

    1. take out date from text in column A
    2. If there are string of numbers not date e.g date format 6 characters ending with 10 or 11 then copy date from column G
    3. if no date in column A use copy date from column G

    I have attached a test file to show the result i am looking if any one could help. Thanks
    Attached Files Attached Files
    Last edited by tek9step; 01-05-2011 at 06:33 AM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: get date from text & cell based on condition

    Here's a UDF that will do it.
    Option Explicit
    
    Function ExtractDate(Rng1 As Range, Rng2 As Range) As Date
    Dim MyArr As Variant
    Dim i As Long
    Dim MyDate As String, MyStr As String
    
    MyArr = Split(Trim(Rng1), " ")
    For i = LBound(MyArr) To UBound(MyArr)
        MyStr = Trim(MyArr(i))
        If IsNumeric(MyStr) And Len(MyStr) = 6 Then
            If Right(MyStr, 2) = 10 Or Right(MyStr, 2) = 11 Then
                ExtractDate = DateSerial(Right(MyStr, 2), Mid(MyStr, 3, 2), Left(MyStr, 2))
                Exit Function
            End If
        End If
    Next i
    
    ExtractDate = Rng2
    
    End Function
    Used in cell I15 as:

    =EXTRACTDATE(A15,G15)

    It will attempt to pull out the date from the first cell, if none is found, it will return the second cell's date.
    Attached Files Attached Files
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

+ 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