+ Reply to Thread
Results 1 to 5 of 5

search a string withing a string : find / search hangs

  1. #1
    Registered User
    Join Date
    10-06-2005
    Posts
    14

    search a string withing a string : find / search hangs

    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

  2. #2
    Registered User
    Join Date
    10-06-2005
    Posts
    14

    i have fogotten:

    i have forgotten to say:

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

  3. #3
    Registered User
    Join Date
    10-06-2005
    Posts
    14

    i have the solution

    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

  4. #4
    Norman Jones
    Guest

    Re: search a string withing a string : find / search hangs

    Hi Itarnak,

    Look at the InStr function in VBA help.


    ---
    Regards,
    Norman



    "itarnak" <itarnak.1xenyd_1130155506.1481@excelforum-nospam.com> wrote in
    message news:itarnak.1xenyd_1130155506.1481@excelforum-nospam.com...
    >
    > 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
    >




  5. #5
    Tom Ogilvy
    Guest

    Re: 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" <itarnak.1xeqqe_1130159129.9093@excelforum-nospam.com> wrote in
    message news:itarnak.1xeqqe_1130159129.9093@excelforum-nospam.com...
    >
    > 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1