+ Reply to Thread
Results 1 to 10 of 10

Formulas for Counting and Displaying Text String Recurrences

  1. #1
    Registered User
    Join Date
    10-03-2013
    Location
    Chicago, United States
    MS-Off Ver
    Excel 2010
    Posts
    11

    Formulas for Counting and Displaying Text String Recurrences

    Hello,

    I have a column of text strings and blank cells and I'd like to develop cell formula #1 to display the most common string occurrence, and cell formula #2 to count the number of occurrences of a specific string in a separate cell.

    Here's an example of the column of strings:


    Harvard, Yale
    Yale, UCLA
    Berkeley
    Yale
    Harvard


    And then the output table would look like this:

    Most Common: Formula #1 returns "Yale"
    Search: [Text Entry] = "Harvard"
    # Occurrences: Formula #2 returns 2

    I've found similar formulas to count repeating text strings, but none that have been able to count string recurrences within a cell (i.e. "Harvard, Yale").

    Any help would be much appreciated!

    -thegivenbeing

  2. #2
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Formulas for Counting and Displaying Text String Recurrences

    Formula 2 would be

    =COUNTIF(A:A,"*Harvard*")

    Formula 1 will require a little more thought.

    Is there a list of the words to include in the search for most common, or do you just want any word found in the cells?

  3. #3
    Registered User
    Join Date
    10-03-2013
    Location
    Chicago, United States
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Formulas for Counting and Displaying Text String Recurrences

    Oh of course for Formula #2! Thanks for that.

    As for Formula #1, ideally i would like it to search for any word. If that's impossible though, an alternative would be to search for a word in separate table.

  4. #4
    Forum Expert
    Join Date
    02-19-2013
    Location
    India
    MS-Off Ver
    07/16
    Posts
    2,386

    Re: Formulas for Counting and Displaying Text String Recurrences

    can you attach a sample book
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    WANT TO SAY THANKS, HIT ADD REPUTATION (*) AT THE BOTTOM LEFT CORNER OF THE POST

    More we learn about excel, more it shows us, how less we know about it.

    for chemistry
    https://www.youtube.com/c/chemistrybyshivaansh

  5. #5
    Forum Expert
    Join Date
    02-19-2013
    Location
    India
    MS-Off Ver
    07/16
    Posts
    2,386

    Re: Formulas for Counting and Displaying Text String Recurrences

    to count the string lets say "Harvard, Yale"
    use in A8 assuming your data is present in A1 to A6

    =(SUM(LEN(A1:A6))-SUM(LEN(SUBSTITUTE(A1:A6,"Harvard, Yale",""))))/LEN("Harvard, Yale")
    copy paste above then hold control and shift then hit enter to make it array formula

    other approach may be
    =SUM(--(MMULT(--(IFERROR(SEARCH({"harvard","Yale"},A1:A6),0)>0),{1;1})=2))
    Last edited by hemesh; 01-15-2016 at 03:56 PM.

  6. #6
    Registered User
    Join Date
    10-03-2013
    Location
    Chicago, United States
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Formulas for Counting and Displaying Text String Recurrences

    Hi hemesh,

    Thanks for your help. The only issue is that I need the formula to dynamically update (i.e. not be pre-defined for "Harvard, Yale"). So as my source table changes, the text displayed by the formula for "Most Common" might change.

    I didn't realize this at first, but the same issue exists for Formula #2 as well. The formula jason.b75 gave doesn't count as the value entered for "Search" is updated.

    I've attached a sample workbook though in case that helps.

    -thegivenbeing

  7. #7
    Forum Expert
    Join Date
    02-19-2013
    Location
    India
    MS-Off Ver
    07/16
    Posts
    2,386

    Re: Formulas for Counting and Displaying Text String Recurrences

    u need to use formula as
    =COUNTIF(A:A,"*"&D3&"*")

  8. #8
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Formulas for Counting and Displaying Text String Recurrences

    The formula was just an example based on what you said in post #1, with the "search" value in B1, you could use

    =COUNTIF(A:A,"*"&B1&"*")

    Still trying to work out formula #1, think that might need vba though, it seems to be beyond what is reasonably practical with native formula functions.

  9. #9
    Registered User
    Join Date
    10-03-2013
    Location
    Chicago, United States
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Formulas for Counting and Displaying Text String Recurrences

    Thanks hemesh and jason.b75. That makes sense re: Formula #2.

    If it seems too arduous (or near impossible) to devise the code for Formula #1, then I could also make use of VBA. It just might require some extra tweaking, given the final report structure.

  10. #10
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Formulas for Counting and Displaying Text String Recurrences

    See if this UDF does what you need, copy the code to the vba editor,
    Please Login or Register  to view this content.
    Then use the formula in the worksheet to get the most common word

    =MAX_OCCURRENCE(A1:A10)

    I would suggest using a suitable sized range in the formula rather than whole columns, I haven't tried with an entire column but I would imagine processing would be very slow.

    In the event of a tie, the word found earliest in the list will be returned.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Counting recurrences of a month
    By tonnyfm in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-29-2013, 02:31 AM
  2. [SOLVED] HOW TO....Find a word in a text string then displaying in another cell ?
    By Jedski in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-11-2012, 02:10 PM
  3. Replies: 9
    Last Post: 10-17-2011, 04:33 PM
  4. Searching a string of text and displaying it's corresponding value
    By ole_gunner11 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-16-2010, 07:46 AM
  5. Displaying Long text after deleting formulas
    By Dohko in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-10-2009, 04:55 PM
  6. Replies: 3
    Last Post: 02-06-2008, 06:40 AM
  7. [SOLVED] Locate and count the recurrences of a text string
    By Trish2 in forum Excel General
    Replies: 1
    Last Post: 03-08-2006, 11:10 AM

Tags for this Thread

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