+ Reply to Thread
Results 1 to 6 of 6

Counting Multiple Occurrences of Text in a Cell

Hybrid View

  1. #1
    Forum Contributor bentleybob's Avatar
    Join Date
    02-27-2009
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    644

    Counting Multiple Occurrences of Text in a Cell

    Looking for the most efficient way to determine the position of the LAST occurrence of specific text in a cell. So, if A1 contained AbcdefgAhijklmAnopqrstAuvwxyAz, and my criterion was "A", then I would like the formula in B1 to return 29.

    It's annoying that neither FIND nor SEARCH has an "occurrence" option. I can build a compund formula using multiple uses of FIND, but it's hugely inefficient since I don't know what the maximum number of occurrences will be.

    Thanks in advance.
    Last edited by bentleybob; 05-02-2011 at 01:46 PM.

  2. #2
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: Counting Multiple Occurrences of Text in a Cell

    Chip has this array formula to find last occurence of charcetr in B1 from string in A1

    =MAX((MID(A1,ROW(INDIRECT("A1:A"&LEN(A1))),1)=B1)*ROW(INDIRECT("A1:A"&LEN(A1))))

    EDIT can be found here

  3. #3
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Counting Multiple Occurrences of Text in a Cell

    With
    A1: containing text.....e.g. AbcdefgAhijklmAnopqrstAuvwxyAz
    B1: a character to find...e.g. A

    This regular formula returns the position of the last occurrence of that character
     
    C1: =FIND("|",SUBSTITUTE(A1,"A","|",LEN(A1)-LEN(SUBSTITUTE(A1,"A",""))))
    In the above example, the formula returns: 29

    Note: That formula is case-sensitive...so if A1 contains lower case a's, they would be ignored.
    If you need it to NOT be case-sensitive...try this:
    C1: =FIND("|",SUBSTITUTE(UPPER(A1),B1,"|",LEN(A1)-LEN(SUBSTITUTE(A1,"A",""))))


    Is that something you can work with?
    Last edited by Ron Coderre; 04-30-2011 at 03:13 PM.
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  4. #4
    Forum Contributor bentleybob's Avatar
    Join Date
    02-27-2009
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    644

    Re: Counting Multiple Occurrences of Text in a Cell

    Both formulas are very efficient. But Arthur: for some reason, I get a result of 1 (see the attached). Ron's formula gives me the correct result. Thanks very much to you both!
    Attached Files Attached Files

  5. #5
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: Counting Multiple Occurrences of Text in a Cell

    As I indicated it is an array formula, so, it should be committed with Ctrl+Shift+Enter

  6. #6
    Forum Contributor bentleybob's Avatar
    Join Date
    02-27-2009
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    644

    Re: Counting Multiple Occurrences of Text in a Cell

    It didn't work for me the first time, but I see now that it does, in fact, work as an array formula. So sorry for having doubted your advice! And I also appreciate the link you attached as it answered another question I had, which was to be able to identify the nth occurrence. Thanks much.

+ 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