Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default search a string withing a string : find / search hangs


hi,

i want to know if a string is within another string. If i us
find/search, the function hangs if the string is not found.....instea
of return an "not found code", as i expected...


So which function to use to find a string in another one?


Regards,
iTarna

--
itarna
-----------------------------------------------------------------------
itarnak's Profile: http://www.excelforum.com/member.php...fo&userid=2786
View this thread: http://www.excelforum.com/showthread.php?threadid=47873

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default search a string withing a string : find / search hangs

Hi Itarnak,

Look at the InStr function in VBA help.


---
Regards,
Norman



"itarnak" wrote in
message ...

hi,

i want to know if a string is within another string. If i use
find/search, the function hangs if the string is not found.....instead
of return an "not found code", as i expected...


So which function to use to find a string in another one?


Regards,
iTarnak


--
itarnak
------------------------------------------------------------------------
itarnak's Profile:
http://www.excelforum.com/member.php...o&userid=27865
View this thread: http://www.excelforum.com/showthread...hreadid=478738



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default search a string withing a string : find / search hangs


i have forgotten to say:

the strings are not in cells.values: they are in hyperlinks
(hyperlink.address

--
itarna
-----------------------------------------------------------------------
itarnak's Profile: http://www.excelforum.com/member.php...fo&userid=2786
View this thread: http://www.excelforum.com/showthread.php?threadid=47873

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default search a string withing a string : find / search hangs


That works great

Function searchStr(searchedStr, otherStr)
On Error GoTo errorHandler
indice = Application.WorksheetFunction.Find(searchedStr, otherStr)
searchStr = indice
Exit Function

errorHandler:
On Error GoTo 0
searchStr = -1
End Functio

--
itarna
-----------------------------------------------------------------------
itarnak's Profile: http://www.excelforum.com/member.php...fo&userid=2786
View this thread: http://www.excelforum.com/showthread.php?threadid=47873

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default search a string withing a string : find / search hangs

that would be one of the slower ways to do it:

Function searchStr(searchedStr, otherStr)
On Error GoTo errorHandler
indice = Instr(1,searchedStr, otherStr,vbTextCompare)
searchStr = indice
Exit Function

errorHandler:
On Error GoTo 0
searchStr = -1
End Function

if you want it to be case sensitive like FIND ("A" < "a"), then change
vbTextCompare to vbBinaryCompare

or just call instr directly instead of reinventing the wheel.

--
Regards,
Tom Ogilvy



"itarnak" wrote in
message ...

That works great

Function searchStr(searchedStr, otherStr)
On Error GoTo errorHandler
indice = Application.WorksheetFunction.Find(searchedStr, otherStr)
searchStr = indice
Exit Function

errorHandler:
On Error GoTo 0
searchStr = -1
End Function


--
itarnak
------------------------------------------------------------------------
itarnak's Profile:

http://www.excelforum.com/member.php...o&userid=27865
View this thread: http://www.excelforum.com/showthread...hreadid=478738



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
Find specific info using search string using VBA laavista Excel Discussion (Misc queries) 5 May 20th 09 07:59 PM
Search/Match/Find ANY part of string to ANY part of Cell Value TWhizTom Excel Worksheet Functions 0 July 21st 08 08:16 PM
FIND / SEARCH text compare cell to string in 3rd cell nastech Excel Discussion (Misc queries) 0 October 29th 07 02:51 AM
to search for a string and affect data if it finds the string? Shwaman Excel Worksheet Functions 1 January 11th 06 12:56 AM
VBA function : How to search a string in another string? bibi-phoque Excel Programming 5 April 19th 05 06:24 PM


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