extract Date from string in Cell vba

HebertsYES

New Member
Joined
Oct 4, 2014
Messages
15
I have a cell that contains the following info:

Thu, Jan 29, 2015 at 9:33 PM, windyknollgoldens@gmail.com <windyknollgoldens@gmail.com> wrote:

The format will always stay the same, the date and email address will change.
what I need is to extract only the date from this string and put it into another cell. I do not want the time.
Can anyone tell me what vba code to use for this?</windyknollgoldens@gmail.com>
 
Last edited:

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Select one of the cells and try running this.
Code:
Sub t()
Dim dt As Variant, myDate As string
dt = Split(ActiveCell.Value, ",")
myDate = dt(1) & ", " & dt(2)
MsgBox myDate
End Sub
 
Upvote 0
day
Code:
=MID(A1;FIND(" ";A1;FIND(" ";A1;1)+1)+1;2)
month
Code:
=MONTH(DATEVALUE(TRIM(MID(A1;FIND(", ";A1;1)+1;FIND(", ";A1;FIND(", ";A1;1))))&" 1 "))
year
Code:
=TRIM(MID(A1;FIND(", ";A1;FIND(", ";A1;1)+1)+1;5))
 
Upvote 0
Here is another way to do it with VBA code...

Code:
Sub Test()
  Dim Text As String, MyDate As String
  Text = ActiveCell.Value
  MyDate = Trim(Mid(Left(Text, InStr(Text, " at ")), InStr(Text, ",") + 1))
  MsgBox MyDate
End Sub

The above code returns the date as a text string, but if you want it to return a real date (which you can use the Format function on to display it in the form you want...

Code:
Sub Test()
  Dim Text As String, MyDate As Date
  Text = ActiveCell.Value
  MyDate = CDate(Mid(Left(Text, InStr(Text, " at ")), InStr(Text, ",") + 1))
  MsgBox Format(MyDate, "mmm d, yyyy")
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

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