LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #12   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




 
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 11:59 AM.

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"