+ Reply to Thread
Results 1 to 5 of 5

Return position of 2nd, 3rd, ect occurrence of a character in a st

  1. #1
    jheby
    Guest

    Return position of 2nd, 3rd, ect occurrence of a character in a st

    the Excel =FIND command returns the position of the first instance of a
    string that it finds. Is there any way to find position of the 2nd, 3rd, or
    nth occurrence? Using =MID is too messy.

  2. #2
    bpeltzer
    Guest

    RE: Return position of 2nd, 3rd, ect occurrence of a character in a st

    You could nest the find commands, using the result of the first, plus 1, as
    the starting point for the next:
    =FIND("a",A1,FIND("a",A1)+1) finds the second "a" within cell A2, for
    instance.
    =FIND("a",A1,FIND("a",A1,FIND("a",A1)+1)+1) finds the third.
    Of course, this is subject to Excel's limit of seven levels of nesting.

    "jheby" wrote:

    > the Excel =FIND command returns the position of the first instance of a
    > string that it finds. Is there any way to find position of the 2nd, 3rd, or
    > nth occurrence? Using =MID is too messy.


  3. #3
    Ron Coderre
    Guest

    RE: Return position of 2nd, 3rd, ect occurrence of a character in a st

    Try something like this:

    For a text value in A1

    B1: =FIND(CHAR(7),SUBSTITUTE(A1,"a",CHAR(7),3))

    That formula finds the position of the 3rd instance of the letter "a" in
    Cell A1

    Note: Char(7) is ASCII for the Bell sound...unlikely that it's in your
    string, right?

    Does that help?

    ***********
    Regards,
    Ron

    XL2002, WinXP-Pro


    "jheby" wrote:

    > the Excel =FIND command returns the position of the first instance of a
    > string that it finds. Is there any way to find position of the 2nd, 3rd, or
    > nth occurrence? Using =MID is too messy.


  4. #4
    Biff
    Guest

    Re: Return position of 2nd, 3rd, ect occurrence of a character in a st

    Hi!

    Try this:

    =FIND("~",SUBSTITUTE(A1,"x","~",B1))

    Searching for "x". B1 holds the instance you want.

    Note: Substitute is case sensitive. To make it a little more robust:

    =FIND("~",SUBSTITUTE(UPPER(A1),"X","~",B1))

    "~" is used as a "marker". The marker needs to be some char or group of
    chars that are more than likely not to appear in the string.

    Biff

    "jheby" <[email protected]> wrote in message
    news:[email protected]...
    > the Excel =FIND command returns the position of the first instance of a
    > string that it finds. Is there any way to find position of the 2nd, 3rd,
    > or
    > nth occurrence? Using =MID is too messy.




  5. #5
    Ron Rosenfeld
    Guest

    Re: Return position of 2nd, 3rd, ect occurrence of a character in a st

    On Tue, 14 Feb 2006 11:12:26 -0800, "jheby" <[email protected]>
    wrote:

    >the Excel =FIND command returns the position of the first instance of a
    >string that it finds. Is there any way to find position of the 2nd, 3rd, or
    >nth occurrence? Using =MID is too messy.


    Download and install Longre's free morefunc.xll add-in from
    http://xcell05.free.fr


    Then use the formula:

    =REGEX.FIND(StringToSearch, StringToFind, n)

    where 'n' is the instance number of the string.

    For a case-INsensitive version:

    =REGEX.FIND(StringToSearch, StringToFind, n, FALSE)


    --ron

+ 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