+ Reply to Thread
Results 1 to 5 of 5

Counting strings in string

  1. #1
    Registered User
    Join Date
    11-03-2006
    Posts
    18

    Counting strings in string

    Hello all,

    I'm looking for a worksheet function that can count the number of occurrences of a string in a cell. For instance the Number of "e"'s in "ajheweewhhdswweeeces".

    thnx,

    Jivo

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Hi,

    try

    =LEN(A1)-LEN(SUBSTITUTE(A1,"e",""))

    VBA Noob

  3. #3
    Forum Expert oldchippy's Avatar
    Join Date
    02-14-2005
    Location
    Worcester, UK
    MS-Off Ver
    Excel 2007 (Home)
    Posts
    7,097

    Thumbs up

    Quote Originally Posted by Jivo
    Hello all,

    I'm looking for a worksheet function that can count the number of occurrences of a string in a cell. For instance the Number of "e"'s in "ajheweewhhdswweeeces".

    thnx,

    Jivo
    hi Jivo,

    Try

    =LEN(A1)-LEN(SUBSTITUTE(A1,"e",""))

    oldchippy

  4. #4
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,524
    Yahoo says this is the best answer

    '1st Step - Write a macro (it needs to be in a module)
    '—Open your spreadsheet
    '—Alt F11
    '—Right-Click on your spreadsheet; Insert | Module
    '—Paste this macro in the module

    Please Login or Register  to view this content.
    'The macro creates a UDF (User Defined Function) to count characters

    '2nd Step - Create formulas using the new function to count the letters in your string.
    'For sake of ease I will assume that your string is in A1
    '—Create the list of letters to check in B1:B26 (Type a in B1, b in B2...)
    'Make sure to use lowercase letters.
    '—Type this formula in C1: =CC(LOWER($A$1),B1)
    'Lower is needed in the formula to ensure both upper- and lowercase letters are counted.
    '—Copy the formula down alongside the alphabet

    'You will now have three things; your string in A1, A through Z in Column B and in Column C you will have count alongside the corresponding letter in Column B

  5. #5
    Registered User
    Join Date
    11-03-2006
    Posts
    18

    Talking

    Thanx all for the fast reply!

+ 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