+ Reply to Thread
Results 1 to 12 of 12

Count occurrences of text in a range

  1. #1
    Forum Contributor
    Join Date
    06-21-2006
    MS-Off Ver
    2007
    Posts
    141

    Count occurrences of text in a range

    I have a range of cells that contain various text codes. I need to develop a formula that will count each of those individual codes.

    For example, range A1:E1

    A1 - c,ce,v
    B1 - v,c,ve
    C1 - VE,CE,V
    D1 - CE,v,C
    E1 - V,CE,C
    *There is no case sensitivity.

    I am attempting to pull out specific codes such as; how many times is C in the range? The complication I keep running into is trying to account for the commas:

    =COUNTIF($A$1:$E$1,"*C*")
    Last edited by braydon16; 03-18-2013 at 05:23 PM.

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: Count occurrences of text in a range

    is that all in 1 cell?
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Forum Contributor
    Join Date
    06-21-2006
    MS-Off Ver
    2007
    Posts
    141

    Re: Count occurrences of text in a range

    Yes. c,ce,v are all in A1.

  4. #4
    Forum Contributor
    Join Date
    09-27-2012
    Location
    Florida
    MS-Off Ver
    Excel XP to 2013
    Posts
    342

    Re: Count occurrences of text in a range

    You can try this and enter it as an array Ctrl+Shift+Enter because substitute is case sensitive you enter both cases. I'm sure there are 5 other ways to do this but this works.

    Please Login or Register  to view this content.
    Tom S.
    ↙ If you find my reply helpful click on the * down there on the left. Yeah that's it, right there, down on the left
    If your question is resolved, mark it SOLVED using the thread tools.

  5. #5
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Count occurrences of text in a range

    If you want to count "c" and this is the cell entry:

    c,ce,c

    What result do you expect?
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  6. #6
    Forum Contributor
    Join Date
    06-21-2006
    MS-Off Ver
    2007
    Posts
    141

    Re: Count occurrences of text in a range

    I would expect a result of 2. CE is a different code altogether. The above counted "c", but included the CE. So, in your example of c,ce,c it would return a 3. This is a pickle...and to make it more interesting I have to refrain from using VB.

  7. #7
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Count occurrences of text in a range

    braydon16,

    Attached is an example workbook based on the criteria you described and includes Tony Valko's example.
    The sample data is in row 1 from A:F
    The code that you want counted is typed into cell B3
    The number of times that code appears is calculated by this formula in cell B4:
    Please Login or Register  to view this content.

    Does that work for you?
    Attached Files Attached Files
    Last edited by tigeravatar; 03-18-2013 at 05:07 PM.
    Hope that helps,
    ~tigeravatar

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

  8. #8
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Count occurrences of text in a range

    Try this...

    =SUMPRODUCT(LEN(","&A1:E1&",")-LEN(SUBSTITUTE(","&LOWER(A1:E1)&",",LOWER(",c,"),"")))/LEN(",c,")

    EDIT:
    Note that the SUBSTITUTE function is case sensitive which is why we need to use the LOWER(...) function in the formula.
    Last edited by Tony Valko; 03-18-2013 at 05:23 PM.

  9. #9
    Forum Contributor
    Join Date
    06-21-2006
    MS-Off Ver
    2007
    Posts
    141

    Re: Count occurrences of text in a range

    Looks like it works! Thanks all!

  10. #10
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Count occurrences of text in a range

    You're welcome. We appreciate the feedback!

  11. #11
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Count occurrences of text in a range

    This also seems to work and is much shorter:

    =SUM(COUNTIF(A1:E1,{"c,*","*,c,*","*,c"}))

  12. #12
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Count occurrences of text in a range

    Quote Originally Posted by Tony Valko View Post
    This also seems to work and is much shorter:

    =SUM(COUNTIF(A1:E1,{"c,*","*,c,*","*,c"}))
    Just to clarify...

    That will only count each possible charater configuration once per cell.

    For example, if the cell contained:

    c,CE,c,c,CV,c

    The formula would return 3 counting:

    c,CE,c,c,CV,c

+ 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