Extract Date from text

Gregfox

Board Regular
Joined
Apr 12, 2011
Messages
120
Hi all,
I have the following TEXT(not date format):

Stocks - Market value = $1,00.00* Tue Jan 30 2018 4:49:33 pm EDT in Cell A1 sheet 1

I wish to extract the date only to be 1/30/2018 in sheet 2 in cell B3

Note: the dates change like Feb 21 2017, Apr 4 2016 etc.



I tried the MID function after the '*' to no avail.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Assuming there is always as space after the asterisk, use this formula...

=0+REPLACE(MID(A1,FIND("*",A1)+6,11),7,0,",")

and format the cell you put it in with the date format you want for it.
 
Upvote 0
Fix for single digit days...

=0+SUBSTITUTE(REPLACE(MID(A1,FIND("*",A1)+6,11),7,0,",")," ,",", ")
 
Upvote 0
Thank you for the reply.
When I put this into my VBA code it fails. I thought when Iposted this in the VBA Forum it would be understood as VBA code, my Bad.
I should have indicated VBA and PC windows 10, Excel 2007.Sorry.

 
Upvote 0
VBA code
Code:
Sub Macro1()
Ary = Array("", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")


k = InStr(1, Range("A3"), "*") + 6


For Mth = 0 To 12
If Mid(Range("A3"), k, 3) = Ary(Mth) Then Exit For
Next


D_ay = 0 + Trim(Mid(Range("A3"), k + 4, 2))
Yr = 0 + Right(Trim(Mid(Range("A3"), k, 11)), 4)


Range("B3") = DateSerial(Yr, Mth, D_ay)
End Sub
 
Upvote 0
Rick already solved this for you. Just translate what he gave you to VBA:
Code:
Sub Foo()

    Dim dtmDate As Date, _
        strDate$
    
    Let strDate = Sheet1.Range("A1").Text
    Let dtmDate = DateValue(WorksheetFunction.Replace(Mid(strDate, InStr(1, strDate, "*") + 6, 11), 7, 0, ", "))
    Sheet2.Range("B3") = dtmDate
    
    MsgBox Format(dtmDate, "dd-mmm-yy"), vbInformation, "Rick's a Stud"



End Sub
 
Last edited:
Upvote 0
Thank you for the reply.
When I put this into my VBA code it fails. I thought when Iposted this in the VBA Forum it would be understood as VBA code, my Bad.
This is not a VBA Forum, rather, it is just an Excel Forum where questions about Excel can be asked. Anyway, here is the code I posted in Message #2 translated into a VBA macro...
Code:
[table="width: 500"]
[tr]
	[td]Sub GetDateFromCellA1()
  Sheets("Sheet2").Range("B3") = CDate(Evaluate("REPLACE(MID(Sheet1!A1,FIND(""*"",Sheet1!A1)+6,11),7,0,"", "")"))
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
:cry: Jeepers, I was kinda 'xpectin' ol' Rick ta say sumpin' 'bout the title of my message box -- but nuttin'. :cry:
 
Upvote 0

Forum statistics

Threads
1,214,535
Messages
6,120,093
Members
448,944
Latest member
SarahSomethingExcel100

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