+ Reply to Thread
Results 1 to 7 of 7

Counting the number of times a text string occurs in a cell

  1. #1
    Registered User
    Join Date
    06-23-2009
    Location
    Chicago, USA
    MS-Off Ver
    Excel 2003
    Posts
    11

    Counting the number of times a text string occurs in a cell

    This may sound dumb but i'm having trouble getting this to work. I want to return the number of times a text appears in a single cell. So, i have a paragraph of text, within which "text" appears 5 times. What's the best formula to get that value?

    Example paragraph:

    "This article explains how you can use worksheet functions in Microsoft Excel for Mac to count the number of occurrences of a specific number or text string in a range of cells on a worksheet. The "More Information" section of this article contains sample formulas that you can use to do this."

    Key text: "this"

    Output value: 3

    I've thought about using a string of "Find" formulas and starting the nested finds +1 of the previous start number but that seems like a hassle. Thoughts?

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Counting the number of times a text string occurs in a cell

    Hi,

    One way

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    06-23-2009
    Location
    Chicago, USA
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Counting the number of times a text string occurs in a cell

    Thanks Richard.

  4. #4
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Counting the number of times a text string occurs in a cell

    Richards' formula counts the difference in letters and only replaces the capital "This".

    =(LEN(A1)-LEN(SUBSTITUTE(SUBSTITUTE(A1,"This",""),"this","")))/LEN("this")
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  5. #5
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Counting the number of times a text string occurs in a cell

    You could take care of the case issue by using LOWER function like this

    =(LEN(A1)-LEN(SUBSTITUTE(LOWER(A1),"this","")))/LEN("this")

    That will count this, This or THIS or any case combination (but note it would also count thistle or similar.....)
    Audere est facere

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Counting the number of times a text string occurs in a cell

    Quote Originally Posted by ChemistB View Post
    Richards' formula counts the difference in letters and only replaces the capital "This".
    In my version of Excel it calculates the required value 3 which seems to imply it's case insensitive.

  7. #7
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Counting the number of times a text string occurs in a cell

    Quote Originally Posted by Richard Buttrey View Post
    In my version of Excel it calculates the required value 3 which seems to imply it's case insensitive.
    Richard, SUBSTITUTE is definitely case-sensitive (in any version), so in your formula

    =LEN(A1)-LEN(SUBSTITUTE(A1,"This","|"))

    SUBSTITUTE finds the only instance of "This" (right at the start) and replaces it with a single character "|", so that makes the resulting string 3 characters shorter, so in this case, co-incidentally, you are getting the right result, but in fact you are counting 3 for every instance of exactly "This".....so if A1 contains just

    "This Life"

    You'd still get 3....and if you used "this" in place of "This" in your original formula (on the original text) you get 6!

+ 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