+ Reply to Thread
Results 1 to 9 of 9

Count the occurrences of a text string?

  1. #1
    Registered User
    Join Date
    10-28-2009
    Location
    Scotland
    MS-Off Ver
    Excel 2003
    Posts
    2

    Count the occurrences of a text string?

    Hello, I am looking for your help in a problem i have with MS Excel,

    The Spreadsheet includes four worksheets.

    The first worksheet includes staff suggestions, the date they were submitted and who submitted the suggestions.

    In the column 'raised by', the cell values are:

    C1: John Smith
    C2: John Smith, Iain Mills.

    So in this example, i am looking to count the amount of times 'John Smith appears' or the amount of times 'Iain Mills' appears. John smith should be 2 and Iain mills should result in one.

    However, I am only able to produce a formula to count the occurence if there is only one name in the cell but I am looking to count the amount of times the name appears in the column.

    Any help with this would be great.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,431

    Re: Count the occurrences of a text string?

    If you create a table of staff in column G you can use this array formula.
    Commit using CTR+SHIFT+ENTER


    G1: =John Smith
    I1: =COUNT(--(FIND(G1,$C$1:$C$2)>0))
    Attached Files Attached Files
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Count the occurrences of a text string?

    You could perhaps use COUNTIF with wildcards ?

    =COUNTIF($C$1:$C$2,"*"&$G1&"*")

  4. #4
    Valued Forum Contributor
    Join Date
    07-21-2008
    Location
    London, UK
    Posts
    326

    Re: Count the occurrences of a text string?

    Your need to tinker with this, bit fun some VBA for you, best stick with the functions if at all possible as with VBA you can end up in a mess quick

    Edit the range is probably what you need to do
    Please Login or Register  to view this content.

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Count the occurrences of a text string?

    Jack in the UK, I'm not quite sure that does as you expected... I think perhaps you meant to alter your +1 to be a test based on the UBound of myVar ?

  6. #6
    Valued Forum Contributor
    Join Date
    07-21-2008
    Location
    London, UK
    Posts
    326

    Re: Count the occurrences of a text string?

    Quote Originally Posted by DonkeyOte View Post
    Jack in the UK, I'm not quite sure that does as you expected... I think perhaps you meant to alter your +1 to be a test based on the UBound of myVar ?
    Ermm yep thats a b ad one -- oppppssss

    Try this?
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    04-03-2007
    Location
    Auckland, New Zealand
    MS-Off Ver
    2007
    Posts
    137

    Re: Count the occurrences of a text string?

    I know this is an old thread, but I finally got around to writing a udf for counting the next of occurences of a string within another string.

    the below is what I got to, a bit rough but does what it should

    Please Login or Register  to view this content.

  8. #8
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Count the occurrences of a text string?

    If you want to return the Count of one string within another then you can actually use a Substitute and test length of substituted string versus original and divide the difference by length of sub string removed, eg:

    Please Login or Register  to view this content.
    where A1 holds string being searched for and A2 the string being compared.

    The same logic can be applied in terms of VBA if needed.

    Irrespective of whether you use VBA/formula it's often nec. to apply some sort of delimiter to both strings to avoid false positive matches (not illustrated here).

  9. #9
    Registered User
    Join Date
    02-11-2010
    Location
    Maryland, USA
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Count the occurrences of a text string?

    You rock. I was looking for a similar solution and using wildcards in the search string worked perfectly! Thank you sir.

+ 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