Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Finding date in a string

I have an auto generated workbook that I am pulling reports from. In
the very first row I have the following string:
///CST Period Variance Report - Cement (Initial Date: 1/14/2009
Compare Date: 1/13/2009 (Yellow/Change) | Gross Volumes | Operated
Wells)\\\

What I would like to do is pull the first date after initial date and
find that date on another workbook.
I can't even think of how to start. Please help.

Bryan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Finding date in a string

Try this code. I could of looked for the colon instead of Initial date but
incase there was more than one colon I did a little extra checking.

MyStr = "///CST Period Variance Report - Cement (Initial Date: 1/14/2009 " & _
"Compare Date: 1/13/2009 (Yellow/Change) | Gross Volumes | Operated" & _
"Wells)\\\"

StartPos = InStr(MyStr, "Initial Date:")
MyStr = Mid(MyStr, StartPos)
StartPos = InStr(MyStr, ":")
MyStr = Trim(Mid(MyStr, StartPos + 1))
EndPos = InStr(MyStr, " ")
MyDate = DateValue(Trim(Left(MyStr, EndPos - 1)))

"bpotter" wrote:

I have an auto generated workbook that I am pulling reports from. In
the very first row I have the following string:
///CST Period Variance Report - Cement (Initial Date: 1/14/2009
Compare Date: 1/13/2009 (Yellow/Change) | Gross Volumes | Operated
Wells)\\\

What I would like to do is pull the first date after initial date and
find that date on another workbook.
I can't even think of how to start. Please help.

Bryan

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Finding date in a string

Can I change the Mystr equal to cell "a1"?
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Finding date in a string

It is giving me a compile error. Array expected.
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Finding date in a string

I changed only My
Str to equal Range("A1")

'These lines are commented
'MyStr = "///CST Period Variance Report - Cement (Initial Date: 1/14/2009 "
& _
' "Compare Date: 1/13/2009 (Yellow/Change) | Gross Volumes | Operated" & _
' "Wells)\\\"

MyStr = Range("A1")
StartPos = InStr(MyStr, "Initial Date:")
MyStr = Mid(MyStr, StartPos)
StartPos = InStr(MyStr, ":")
MyStr = Trim(Mid(MyStr, StartPos + 1))
EndPos = InStr(MyStr, " ")
MyDate = DateValue(Trim(Left(MyStr, EndPos - 1)))


"bpotter" wrote:

It is giving me a compile error. Array expected.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Finding date in a string

What is giving you a compile error? It is always a good idea to show the
formula or code that is giving you an error so we can see exactly what you
did.

As for you first question (in your other follow up post), you would do this
to get Mystr equal to what is in A1...

Mystr = Range("A1").Value

and use this line of code in place of where Joel first assigns the text
string to the variable.

Oh, and I had a follow up question for you... the text you showed in the
cell... is there any manual linefeeds in there (as my news reader shows) or
is that a single line of text?

--
Rick (MVP - Excel)


"bpotter" wrote in message
...
It is giving me a compile error. Array expected.


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Finding date in a string

No manual linefeeds.
Gary's solution worked great for me.

Thank yuo so much for all the help guys.

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Finding date in a string

Consider:

Function getdate(r As Range, which As Integer) As Date
s = Split(r.Value, " ")
i = 1
For j = 0 To UBound(s)
If IsDate(s(j)) Then
If i = which Then
getdate = s(j)
Exit Function
Else
i = i + 1
End If
End If
Next
End Function

So that if A1 contains:

Now is the time 1/24/2009 for all 12/25/1945 men to

then
=getdate(A1,1) will return 1/24/2009
and
=getdate(A1,2) will return 12/25/1945
--
Gary''s Student - gsnu2007k


"bpotter" wrote:

I have an auto generated workbook that I am pulling reports from. In
the very first row I have the following string:
///CST Period Variance Report - Cement (Initial Date: 1/14/2009
Compare Date: 1/13/2009 (Yellow/Change) | Gross Volumes | Operated
Wells)\\\

What I would like to do is pull the first date after initial date and
find that date on another workbook.
I can't even think of how to start. Please help.

Bryan

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Finding date in a string

With the getdate function where does it store the date so I can find
it in another workbook?

I generate a report every morning with today and yesterday's date. I
then sort the main sheet to several routes and do calculations for
downtime. I then copy all downtime to a corresponding workbook the has
the months downtime in it.

What I would like to happen though is to be able to make it backwords
compatible in case I miss a day and generate a report for last week it
will find the right date in the other workbook and copy my downtime on
the correct sheet.



Bryan

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Finding date in a string

With the getdate function where does it store the date so I can
find it in another workbook?


It is a function... you can assign its output to your variable...

Mystr = getdate(Range("A1"), 1)

--
Rick (MVP - Excel)


  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Finding date in a string

Here is a completely different approach (although if I had to guess, I'd say
your approach may be slightly efficient)...

Function GetDate(ByVal S As String, Which As Long) As Date
Words = Split(S)
For X = 0 To UBound(Words)
If Not IsDate(Words(X)) Then Words(X) = ""
Next
GetDate = Split(WorksheetFunction.Trim(Join(Words)))(Which - 1)
End Function

--
Rick (MVP - Excel)


"Gary''s Student" wrote in message
...
Consider:

Function getdate(r As Range, which As Integer) As Date
s = Split(r.Value, " ")
i = 1
For j = 0 To UBound(s)
If IsDate(s(j)) Then
If i = which Then
getdate = s(j)
Exit Function
Else
i = i + 1
End If
End If
Next
End Function

So that if A1 contains:

Now is the time 1/24/2009 for all 12/25/1945 men to

then
=getdate(A1,1) will return 1/24/2009
and
=getdate(A1,2) will return 12/25/1945
--
Gary''s Student - gsnu2007k


"bpotter" wrote:

I have an auto generated workbook that I am pulling reports from. In
the very first row I have the following string:
///CST Period Variance Report - Cement (Initial Date: 1/14/2009
Compare Date: 1/13/2009 (Yellow/Change) | Gross Volumes | Operated
Wells)\\\

What I would like to do is pull the first date after initial date and
find that date on another workbook.
I can't even think of how to start. Please help.

Bryan


  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Finding date in a string

This is basically your routine, but structured around a For Each loop...

Function GetDate(ByVal S As String, Which As Long) As Date
Words = Split(S)
For Each W In Words
If IsDate(W) Then
X = X + 1
If X = Which Then
GetDate = CDate(W)
Exit For
End If
End If
Next
End Function

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
Here is a completely different approach (although if I had to guess, I'd
say your approach may be slightly efficient)...

Function GetDate(ByVal S As String, Which As Long) As Date
Words = Split(S)
For X = 0 To UBound(Words)
If Not IsDate(Words(X)) Then Words(X) = ""
Next
GetDate = Split(WorksheetFunction.Trim(Join(Words)))(Which - 1)
End Function

--
Rick (MVP - Excel)


"Gary''s Student" wrote in
message ...
Consider:

Function getdate(r As Range, which As Integer) As Date
s = Split(r.Value, " ")
i = 1
For j = 0 To UBound(s)
If IsDate(s(j)) Then
If i = which Then
getdate = s(j)
Exit Function
Else
i = i + 1
End If
End If
Next
End Function

So that if A1 contains:

Now is the time 1/24/2009 for all 12/25/1945 men to

then
=getdate(A1,1) will return 1/24/2009
and
=getdate(A1,2) will return 12/25/1945
--
Gary''s Student - gsnu2007k


"bpotter" wrote:

I have an auto generated workbook that I am pulling reports from. In
the very first row I have the following string:
///CST Period Variance Report - Cement (Initial Date: 1/14/2009
Compare Date: 1/13/2009 (Yellow/Change) | Gross Volumes | Operated
Wells)\\\

What I would like to do is pull the first date after initial date and
find that date on another workbook.
I can't even think of how to start. Please help.

Bryan



  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Finding date in a string

Thanks Rick

Both suggestions are interesting alternatives.
--
Gary''s Student - gsnu200827


"Rick Rothstein" wrote:

This is basically your routine, but structured around a For Each loop...

Function GetDate(ByVal S As String, Which As Long) As Date
Words = Split(S)
For Each W In Words
If IsDate(W) Then
X = X + 1
If X = Which Then
GetDate = CDate(W)
Exit For
End If
End If
Next
End Function

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
Here is a completely different approach (although if I had to guess, I'd
say your approach may be slightly efficient)...

Function GetDate(ByVal S As String, Which As Long) As Date
Words = Split(S)
For X = 0 To UBound(Words)
If Not IsDate(Words(X)) Then Words(X) = ""
Next
GetDate = Split(WorksheetFunction.Trim(Join(Words)))(Which - 1)
End Function

--
Rick (MVP - Excel)


"Gary''s Student" wrote in
message ...
Consider:

Function getdate(r As Range, which As Integer) As Date
s = Split(r.Value, " ")
i = 1
For j = 0 To UBound(s)
If IsDate(s(j)) Then
If i = which Then
getdate = s(j)
Exit Function
Else
i = i + 1
End If
End If
Next
End Function

So that if A1 contains:

Now is the time 1/24/2009 for all 12/25/1945 men to

then
=getdate(A1,1) will return 1/24/2009
and
=getdate(A1,2) will return 12/25/1945
--
Gary''s Student - gsnu2007k


"bpotter" wrote:

I have an auto generated workbook that I am pulling reports from. In
the very first row I have the following string:
///CST Period Variance Report - Cement (Initial Date: 1/14/2009
Compare Date: 1/13/2009 (Yellow/Change) | Gross Volumes | Operated
Wells)\\\

What I would like to do is pull the first date after initial date and
find that date on another workbook.
I can't even think of how to start. Please help.

Bryan




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
Finding string and color the found string Agustus Excel Programming 1 September 20th 06 07:51 PM
finding a name in a string jay d Excel Worksheet Functions 1 June 12th 06 09:25 PM
Finding A string Abilio Excel Programming 8 March 4th 06 11:12 PM
finding what numbers are in a string David Excel Worksheet Functions 3 May 26th 05 10:10 PM
Finding a string FRAN Excel Programming 2 September 24th 03 01:32 PM


All times are GMT +1. The time now is 12:39 PM.

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

About Us

"It's about Microsoft Excel"