Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default find text similar to yyyy-mm-dd in string

I'd like to find the location of each date within a very long string
(loaded to string from text file). The format of the dates is
yyyy-mm-dd. It would be great if I could use "InStr" and "Like"
together somehow, but I don't know how. Any ideas? Thanks.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default find text similar to yyyy-mm-dd in string

Try some code like the following:

Dim S As String
Dim N As Long
S = "asdf2006-12-05asdf" ' whatever
For N = 1 To Len(S) - 10
If Mid(S, N, 10) Like "####-##-##" Then
Debug.Print Mid(S, N, 10)
Exit Sub
End If
Next N



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


wrote in message
oups.com...
I'd like to find the location of each date within a very long
string
(loaded to string from text file). The format of the dates is
yyyy-mm-dd. It would be great if I could use "InStr" and
"Like"
together somehow, but I don't know how. Any ideas? Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default find text similar to yyyy-mm-dd in string

Change

For N = 1 To Len(S) - 10


to
For N = 1 To Len(S) - 9
and remove the Exit Sub if your string can contain more than one
date.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Chip Pearson" wrote in message
...
Try some code like the following:

Dim S As String
Dim N As Long
S = "asdf2006-12-05asdf" ' whatever
For N = 1 To Len(S) - 10
If Mid(S, N, 10) Like "####-##-##" Then
Debug.Print Mid(S, N, 10)
Exit Sub
End If
Next N



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


wrote in message
oups.com...
I'd like to find the location of each date within a very long
string
(loaded to string from text file). The format of the dates is
yyyy-mm-dd. It would be great if I could use "InStr" and
"Like"
together somehow, but I don't know how. Any ideas? Thanks.





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default find text similar to yyyy-mm-dd in string

Thanks Chip. I guess I had just blocked that from my mind from the
start because I thought it would take forever with the length of the
strings I'm working with. They're actually html files that I'm trying
to manipulate & clickthrough.

e.g.
http://www.sec.gov/cgi-bin/browse-ed...company&CIK=ge

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default find text similar to yyyy-mm-dd in string

The string comparison is quite fast, even with very long strings.
For example, even with a 32K string,

S = Application.WorksheetFunction.Rept("A", 32000) & _
"asdf2006-12-05asdf2005-07-04" ' whatever

the code I posted runs without visible pause.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



wrote in message
oups.com...
Thanks Chip. I guess I had just blocked that from my mind from
the
start because I thought it would take forever with the length
of the
strings I'm working with. They're actually html files that I'm
trying
to manipulate & clickthrough.

e.g.
http://www.sec.gov/cgi-bin/browse-ed...company&CIK=ge



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
Convert YYYY, MM, and DD as a single number string rmorrison Excel Discussion (Misc queries) 13 September 20th 08 05:27 PM
Search, find or lookup defined text in text string zzxxcc Excel Worksheet Functions 9 September 6th 07 09:37 PM
Look for similar text and find the largest value and return value Quan Excel Discussion (Misc queries) 6 August 17th 06 04:54 AM
can you find specific text in a string ignoring any other text chriscp Excel Discussion (Misc queries) 1 September 18th 05 09:54 PM
backwards find function to find character in a string of text Ashleigh K. Excel Programming 1 January 14th 04 04:36 PM


All times are GMT +1. The time now is 02:45 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"