Extract the earliest date from text string

Heather515

New Member
Joined
Sep 11, 2021
Messages
22
Office Version
  1. 365
Platform
  1. Windows
Here is what data look like. Need to extract the earliest date from the text string in each cell. See example below. Need a VBA macro because the date size is very large. Thanks.

5/2/19 texttexttext 1/27/18 texttexttext 12/25/19 texttexttext(result) 1/27/18
10/31/21notesnotes notes 5/1/18 texttext(result) 5/1/18
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
I could be possible that your date format is different than mine, but you can try this first:

VBA Code:
Function jec(cell As String)
   With CreateObject("VBscript.RegExp")
     .Global = True
     .Pattern = "(\d{1,2}\/\d{1,2}\/\d{2})"
     Set ar = .Execute(cell)
    
     m = 9999999
     For Each it In ar
        If DateValue(it) < m Then m = DateValue(it)
     Next
     jec = Format(m, "mm/dd/yy")
   End With
End Function

Excel Formula:
=Jec(A1)
 
Upvote 0
Solution
I could be possible that your date format is different than mine, but you can try this first:

VBA Code:
Function jec(cell As String)
   With CreateObject("VBscript.RegExp")
     .Global = True
     .Pattern = "(\d{1,2}\/\d{1,2}\/\d{2})"
     Set ar = .Execute(cell)
   
     m = 9999999
     For Each it In ar
        If DateValue(it) < m Then m = DateValue(it)
     Next
     jec = Format(m, "mm/dd/yy")
   End With
End Function

Excel Formula:
=Jec(A1)
Thanks. This works perfectly.
 
Upvote 0

Forum statistics

Threads
1,214,821
Messages
6,121,762
Members
449,048
Latest member
excelknuckles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top