+ Reply to Thread
Results 1 to 3 of 3

count number of instances of string in a string

  1. #1
    Registered User
    Join Date
    11-28-2008
    Location
    Sydney, Australia
    Posts
    9

    count number of instances of string in a string

    hi - does anyone know how best to use worksheet functions to count the number of instances of a seach string within a cell for example if a cell contains following

    Ghanimeh & Culbert P & MA

    is there a simple way to count the number of instances of "&" symbol ie answer being 2!

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492
    There is a user defined function that will do this nicely. A UDF means you create function in Excel that doesn't exist yet. This page has the code you need to install in your workbook and instructions at the bottom to do it quickly.

    http://www.vbaexpress.com/kb/getarticle.php?kb_id=235

    Once it is installed, you can put your name in cell A1, and then the formula in B1 would simply be:
    Please Login or Register  to view this content.
    I don't know if it helps, but this UDF will also search for a character or character string in range of cells, too. Could be useful.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Valued Forum Contributor
    Join Date
    11-11-2008
    Location
    Euro
    MS-Off Ver
    2007, 2010
    Posts
    470
    Quote Originally Posted by lawrencef View Post
    hi - does anyone know how best to use worksheet functions to count the number of instances of a seach string within a cell for example if a cell contains following

    Ghanimeh & Culbert P & MA

    is there a simple way to count the number of instances of "&" symbol ie answer being 2!
    I assume your data (the string) in cell A1
    We should use the follow formula that combine LEN and SUBSTITUTE function (worksheet function)

    PHP Code: 
    =LEN(A1)-LEN(SUBSTITUTE(A1,"&","")) 
    Last edited by tigertiger; 11-28-2008 at 02:08 AM.

+ 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