Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 150
Default Extracting dates from a String

Hi,

Cells in Column A have strings of the following type:
eg A1:
Billing for the period March 14 2009 to March 13 2010 - Order dated
April 01 2009
In B1 I want the date : 14-Mar-2009
In C1 I want the date: 13-Mar-2010
(to elaborate, only the first two dates in the string need to be
extracted, third and subsequent dates in the string to be ignored)

Thanks in advance for the help.

Regards,
Raj
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
al al is offline
external usenet poster
 
Posts: 363
Default Extracting dates from a String

Try for start date:
=MID(A1,FIND("period",A1)+7,(FIND("to",A1))-(FIND("period",A1)+8))

Stop date:
=MID(A1,FIND("to",A1)+3,(FIND("-",A1))-(FIND("to",A1)+4))


HTH


"Raj" wrote:

Hi,

Cells in Column A have strings of the following type:
eg A1:
Billing for the period March 14 2009 to March 13 2010 - Order dated
April 01 2009
In B1 I want the date : 14-Mar-2009
In C1 I want the date: 13-Mar-2010
(to elaborate, only the first two dates in the string need to be
extracted, third and subsequent dates in the string to be ignored)

Thanks in advance for the help.

Regards,
Raj

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11
Default Extracting dates from a String

On Oct 7, 9:03*pm, Al wrote:
Try for start date:
=MID(A1,FIND("period",A1)+7,(FIND("to",A1))-(FIND("period",A1)+8))

Stop date:
=MID(A1,FIND("to",A1)+3,(FIND("-",A1))-(FIND("to",A1)+4))

HTH



"Raj" wrote:
Hi,


Cells in Column A have strings of the following type:
eg A1:
Billing for the period March 14 2009 to March 13 2010 - Order dated
April 01 2009
In B1 I want the date : 14-Mar-2009
In C1 I want the date: *13-Mar-2010
(to elaborate, only the first two dates in the string need to be
extracted, third and subsequent dates in the string to be ignored)


Thanks in advance for the help.


Regards,
Raj- Hide quoted text -


- Show quoted text -


Thanks. While that worked right for the given string, it did not work
for all the rows as the strings are composed differently. The word
"period" does not precede the first date at all times nor does the "-"
suceed the second date. Is there a way to extract the first two dates
by looking for the first and second occurrences of the standard "mmmm"
months in the String and then compute the dates based on the position
of those strings?

Regards
Raj
  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,934
Default Extracting dates from a String

I think you need to give us a little more information about the structure of
these text strings of yours. Is the month name **always** spelled out? Is
the year **always** a 4-digit number? Is the only character between date
parts the space character (that is, a comma is **never** used between the
day and the year)? Is the word "to" **always** used to separate the two
dates and, if not, can the text separating them be more than one word long?
Could there other numbers before the first date?
--
Rick (MVP - Excel)


"Rajendra" wrote in message
...
On Oct 7, 9:03 pm, Al wrote:
Try for start date:
=MID(A1,FIND("period",A1)+7,(FIND("to",A1))-(FIND("period",A1)+8))

Stop date:
=MID(A1,FIND("to",A1)+3,(FIND("-",A1))-(FIND("to",A1)+4))

HTH



"Raj" wrote:
Hi,


Cells in Column A have strings of the following type:
eg A1:
Billing for the period March 14 2009 to March 13 2010 - Order dated
April 01 2009
In B1 I want the date : 14-Mar-2009
In C1 I want the date: 13-Mar-2010
(to elaborate, only the first two dates in the string need to be
extracted, third and subsequent dates in the string to be ignored)


Thanks in advance for the help.


Regards,
Raj- Hide quoted text -


- Show quoted text -


Thanks. While that worked right for the given string, it did not work
for all the rows as the strings are composed differently. The word
"period" does not precede the first date at all times nor does the "-"
suceed the second date. Is there a way to extract the first two dates
by looking for the first and second occurrences of the standard "mmmm"
months in the String and then compute the dates based on the position
of those strings?

Regards
Raj

  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11
Default Extracting dates from a String

On Oct 7, 11:22 pm, "Rick Rothstein"
wrote:
I think you need to give us a little more information about the structure of
these text strings of yours. Is the month name **always** spelled out? Is
the year **always** a 4-digit number? Is the only character between date
parts the space character (that is, a comma is **never** used between the
day and the year)? Is the word "to" **always** used to separate the two
dates and, if not, can the text separating them be more than one word long?
Could there other numbers before the first date?
--
Rick (MVP - Excel)

"Rajendra" wrote in message

...
On Oct 7, 9:03 pm, Al wrote:



Try for start date:
=MID(A1,FIND("period",A1)+7,(FIND("to",A1))-(FIND("period",A1)+8))


Stop date:
=MID(A1,FIND("to",A1)+3,(FIND("-",A1))-(FIND("to",A1)+4))


HTH


"Raj" wrote:
Hi,


Cells in Column A have strings of the following type:
eg A1:
Billing for the period March 14 2009 to March 13 2010 - Order dated
April 01 2009
In B1 I want the date : 14-Mar-2009
In C1 I want the date: 13-Mar-2010
(to elaborate, only the first two dates in the string need to be
extracted, third and subsequent dates in the string to be ignored)


Thanks in advance for the help.


Regards,
Raj- Hide quoted text -


- Show quoted text -


Thanks. While that worked right for the given string, it did not work
for all the rows as the strings are composed differently. The word
"period" does not precede the first date at all times nor does the "-"
suceed the second date. Is there a way to extract the first two dates
by looking for the first and second occurrences of the standard "mmmm"
months in the String and then compute the dates based on the position
of those strings?

Regards
Raj


The month name is almost always spelled out in full : January,
February and so on. There are are a few instances of Jan or Feb in the
data.
Year is always a 4 digit number
The separator between dates is always either "to" or "To" or
"tp" (misspelling)
There are no numbers before the first date.
The dates are of the type: (actually more than I initially thought):
November 24th 2008 To May 23rd 2009
12th November 2008 To 11th November 2009
June 20 2009 to June 19 2010
1st Dec 08 tp 31st Dec 08

Thanks and Regards,
Raj



  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,934
Default Extracting dates from a String

The month name is almost always spelled out in full : January,
February and so on. There are are a few instances of Jan or Feb in the
data.
Year is always a 4 digit number
The separator between dates is always either "to" or "To" or
"tp" (misspelling)
There are no numbers before the first date.
The dates are of the type: (actually more than I initially thought):
November 24th 2008 To May 23rd 2009
12th November 2008 To 11th November 2009
June 20 2009 to June 19 2010
1st Dec 08 tp 31st Dec 08


Your say in your 2nd answer that the year is always a 4-digit number, but
then in your last line you show dates with 2-digit years... do we have to
account for 2-digit years or not?

--
Rick (MVP - Excel)

  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,934
Default Extracting dates from a String

See if the following macro does what you want. I assumed the starting row
for your data was Row 2 and that the column containing your text data is
Column A (you can change each of these as necessary in the obvious Const
statements); also, the split out dates are placed in the next two columns to
the right of the specified column containing your text data.

Sub SplitOutDates()
Dim X As Long, Z As Long, LastRow As Long
Dim FirstDate As Date, SecondDate As Date
Dim Txt As String, Parts() As String
Const StartRow = 2
Const DataCol = "A"
LastRow = Cells(Rows.Count, DataCol).End(xlUp).Row
For X = StartRow To LastRow
Txt = Cells(X, DataCol)
Txt = Replace(Txt, "tp", "to", 1, -1, Compa=vbTextCompare)
Txt = Replace(Txt, "st", "", 1, -1, vbTextCompare)
Txt = Replace(Txt, "nd", "", 1, -1, vbTextCompare)
Txt = Replace(Txt, "rd", "", 1, -1, vbTextCompare)
Txt = Replace(Txt, "th", "", 1, -1, vbTextCompare)
Parts = Split(" " & Txt & " ", " to ", -1, vbTextCompare)
On Error GoTo Continue
For Z = 0 To UBound(Parts) - 1
If UBound(Split(Parts(Z))) 2 Then
FirstDate = Split(WorksheetFunction.Substitute(Parts(Z), " ", _
Chr$(1), UBound(Split(Parts(Z))) - 2), Chr$(1))(1)
SecondDate = Split(WorksheetFunction.Substitute(Parts(Z + 1), _
" ", Chr$(1), 3), Chr$(1))(0)
Exit For
End If
Continue:
Next
Cells(X, DataCol).Offset(0, 1).Value = FirstDate
Cells(X, DataCol).Offset(0, 2).Value = SecondDate
Next
End Sub

--
Rick (MVP - Excel)


"Rajendra" wrote in message
...
On Oct 7, 11:22 pm, "Rick Rothstein"
wrote:
I think you need to give us a little more information about the structure
of
these text strings of yours. Is the month name **always** spelled out? Is
the year **always** a 4-digit number? Is the only character between date
parts the space character (that is, a comma is **never** used between the
day and the year)? Is the word "to" **always** used to separate the two
dates and, if not, can the text separating them be more than one word
long?
Could there other numbers before the first date?
--
Rick (MVP - Excel)

"Rajendra" wrote in message

...
On Oct 7, 9:03 pm, Al wrote:



Try for start date:
=MID(A1,FIND("period",A1)+7,(FIND("to",A1))-(FIND("period",A1)+8))


Stop date:
=MID(A1,FIND("to",A1)+3,(FIND("-",A1))-(FIND("to",A1)+4))


HTH


"Raj" wrote:
Hi,


Cells in Column A have strings of the following type:
eg A1:
Billing for the period March 14 2009 to March 13 2010 - Order dated
April 01 2009
In B1 I want the date : 14-Mar-2009
In C1 I want the date: 13-Mar-2010
(to elaborate, only the first two dates in the string need to be
extracted, third and subsequent dates in the string to be ignored)


Thanks in advance for the help.


Regards,
Raj- Hide quoted text -


- Show quoted text -


Thanks. While that worked right for the given string, it did not work
for all the rows as the strings are composed differently. The word
"period" does not precede the first date at all times nor does the "-"
suceed the second date. Is there a way to extract the first two dates
by looking for the first and second occurrences of the standard "mmmm"
months in the String and then compute the dates based on the position
of those strings?

Regards
Raj


The month name is almost always spelled out in full : January,
February and so on. There are are a few instances of Jan or Feb in the
data.
Year is always a 4 digit number
The separator between dates is always either "to" or "To" or
"tp" (misspelling)
There are no numbers before the first date.
The dates are of the type: (actually more than I initially thought):
November 24th 2008 To May 23rd 2009
12th November 2008 To 11th November 2009
June 20 2009 to June 19 2010
1st Dec 08 tp 31st Dec 08

Thanks and Regards,
Raj


  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11
Default Extracting dates from a String

On Oct 8, 2:13 am, "Rick Rothstein"
wrote:
See if the following macro does what you want. I assumed the starting row
for your data was Row 2 and that the column containing your text data is
Column A (you can change each of these as necessary in the obvious Const
statements); also, the split out dates are placed in the next two columns to
the right of the specified column containing your text data.

Sub SplitOutDates()
Dim X As Long, Z As Long, LastRow As Long
Dim FirstDate As Date, SecondDate As Date
Dim Txt As String, Parts() As String
Const StartRow = 2
Const DataCol = "A"
LastRow = Cells(Rows.Count, DataCol).End(xlUp).Row
For X = StartRow To LastRow
Txt = Cells(X, DataCol)
Txt = Replace(Txt, "tp", "to", 1, -1, Compa=vbTextCompare)
Txt = Replace(Txt, "st", "", 1, -1, vbTextCompare)
Txt = Replace(Txt, "nd", "", 1, -1, vbTextCompare)
Txt = Replace(Txt, "rd", "", 1, -1, vbTextCompare)
Txt = Replace(Txt, "th", "", 1, -1, vbTextCompare)
Parts = Split(" " & Txt & " ", " to ", -1, vbTextCompare)
On Error GoTo Continue
For Z = 0 To UBound(Parts) - 1
If UBound(Split(Parts(Z))) 2 Then
FirstDate = Split(WorksheetFunction.Substitute(Parts(Z), " ", _
Chr$(1), UBound(Split(Parts(Z))) - 2), Chr$(1))(1)
SecondDate = Split(WorksheetFunction.Substitute(Parts(Z + 1), _
" ", Chr$(1), 3), Chr$(1))(0)
Exit For
End If
Continue:
Next
Cells(X, DataCol).Offset(0, 1).Value = FirstDate
Cells(X, DataCol).Offset(0, 2).Value = SecondDate
Next
End Sub

--
Rick (MVP - Excel)

"Rajendra" wrote in message

...

On Oct 7, 11:22 pm, "Rick Rothstein"
wrote:
I think you need to give us a little more information about the structure
of
these text strings of yours. Is the month name **always** spelled out? Is
the year **always** a 4-digit number? Is the only character between date
parts the space character (that is, a comma is **never** used between the
day and the year)? Is the word "to" **always** used to separate the two
dates and, if not, can the text separating them be more than one word
long?
Could there other numbers before the first date?
--
Rick (MVP - Excel)


"Rajendra" wrote in message


...
On Oct 7, 9:03 pm, Al wrote:


Try for start date:
=MID(A1,FIND("period",A1)+7,(FIND("to",A1))-(FIND("period",A1)+8))


Stop date:
=MID(A1,FIND("to",A1)+3,(FIND("-",A1))-(FIND("to",A1)+4))


HTH


"Raj" wrote:
Hi,


Cells in Column A have strings of the following type:
eg A1:
Billing for the period March 14 2009 to March 13 2010 - Order dated
April 01 2009
In B1 I want the date : 14-Mar-2009
In C1 I want the date: 13-Mar-2010
(to elaborate, only the first two dates in the string need to be
extracted, third and subsequent dates in the string to be ignored)


Thanks in advance for the help.


Regards,
Raj- Hide quoted text -


- Show quoted text -


Thanks. While that worked right for the given string, it did not work
for all the rows as the strings are composed differently. The word
"period" does not precede the first date at all times nor does the "-"
suceed the second date. Is there a way to extract the first two dates
by looking for the first and second occurrences of the standard "mmmm"
months in the String and then compute the dates based on the position
of those strings?


Regards
Raj


The month name is almost always spelled out in full : January,
February and so on. There are are a few instances of Jan or Feb in the
data.
Year is always a 4 digit number
The separator between dates is always either "to" or "To" or
"tp" (misspelling)
There are no numbers before the first date.
The dates are of the type: (actually more than I initially thought):
November 24th 2008 To May 23rd 2009
12th November 2008 To 11th November 2009
June 20 2009 to June 19 2010
1st Dec 08 tp 31st Dec 08


Thanks and Regards,
Raj


Rick,

It worked like magic. Thanks a Ton

Regards,
Raj


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Extracting h:mm:ss from text string Micki Excel Worksheet Functions 19 January 26th 09 05:26 PM
extracting data from a string Iguss Excel Worksheet Functions 4 November 19th 07 09:50 PM
Extracting a string Peter Rooney Excel Discussion (Misc queries) 5 June 20th 06 06:34 PM
Extracting from a text string AmyTaylor Excel Worksheet Functions 3 June 24th 05 01:34 PM
extracting numbers from string Chris Dowell via OfficeKB.com Excel Discussion (Misc queries) 1 January 12th 05 09:37 PM


All times are GMT +1. The time now is 10:29 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"