ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   search a string withing a string : find / search hangs (https://www.excelbanter.com/excel-programming/343647-search-string-withing-string-find-search-hangs.html)

itarnak[_9_]

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


Norman Jones

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




itarnak[_11_]

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


itarnak[_10_]

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


Tom Ogilvy

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





All times are GMT +1. The time now is 04:43 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com