Extract Month From A Text String

G

George

Good Day,

I have a date that I'm pulling from a report that is in a text string
format. What i need to be able to do is extract the month from the string so
that I can run a script against the month name. The format of the string is
as follows.

Wednesday, April 14, 2010

Thanks in advance for your help.
Sam
 
M

Mike H

Hi,

Maybe this

= MID(A1, FIND(" ",A1,1)+1, FIND(" ",A1,FIND(" ",A1,1)+1)-(FIND("
",A1,FIND(" ",A1,1))))
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.
 
B

Bernard Liengme

=MID(A1,FIND(",",A1)+2,FIND(" ",A1,FIND(",",A1)+2)-FIND(",",A1)-2)
best wishes
 
G

George

Hey Guys,

Thanks for the quick response...It's exactly what I needed and works
perfectly..

George
 
C

Charlize

VBA Code:
--------------------


Sub Give_month()
Dim thedate As String
'the stringdate is placed in a cell
'the cursor is located on that cell when you
'run this code
thedate = Split(Trim(Split(ActiveCell.Text, ",")(1)), " ")(0)
MsgBox thedate
End Sub
--------------------


When you want to incorporate this in your coding, replac
activecell.text with the variable you are using for the loop.

Charlize
 
R

Ron Rosenfeld

Good Day,

I have a date that I'm pulling from a report that is in a text string
format. What i need to be able to do is extract the month from the string so
that I can run a script against the month name. The format of the string is
as follows.

Wednesday, April 14, 2010

Thanks in advance for your help.
Sam

Assuming the text string is always the entire contents of the line, and is
always formatted as
dddd, mmmm dd, yyyy
or
dddd, mmmm d, yyyy

Then
=--MID(A1,FIND(",",A1)+2,99)
or
=DATEVALUE(MID(A1,FIND(",",A1)+2,99))

will return a number which is the Excel Date. (40282 for the above date).

You can then extract the month as a number [1-12] using the MONTH worksheet
function:

=MONTH(--MID(A1,FIND(",",A1)+2,99))

If you want the month as text, then:

=TEXT(--MID(A1,FIND(",",A1)+2,99),"mmmm")

--ron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top