View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
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