+ Reply to Thread
Results 1 to 6 of 6

How to count occurrence of items occurring both singly or in a string within a cell

  1. #1
    Forum Contributor
    Join Date
    08-23-2010
    Location
    uk
    MS-Off Ver
    365 on Mac
    Posts
    146

    How to count occurrence of items occurring both singly or in a string within a cell

    Hi
    I am using excel (2003) to record some data which is shown either as a single variable in a cell (A or 1 for example) or as a string in a cell (A B C or 1 2 3 for example).
    I want to be able to count how many of each variable occur in a column, but am unsure how to do it. I can count it in a possible string, using the criterion: "*A*" or on its own: "A", but can't make it work when it could be either part of a string or just a single letter or number in the cell.
    I hope this makes sense. Sure there must be a simple answer!
    Thanks
    Last edited by Supersadie; 08-23-2010 at 06:08 AM.

  2. #2
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,444

    Re: How to count occurrence of items occurring both singly or in a string within a ce

    Hi,

    If you only have a single occurance of the character you wish to check for in any given cellm then =COUNTIF(A2:A7,"A*") should work. However, if there is any cell that contains more than one occurance of the character, this array may work for you

    =SUM(LEN(A2:A7)-LEN(SUBSTITUTE(A2:A7,"A","")))

    confirm with CTRL, SHIFT and ENTER.
    Rule 1: Never merge cells
    Rule 2: See rule 1

    "Tomorrow I'm going to be famous. All I need is a tennis racket and a hat".

  3. #3
    Forum Contributor
    Join Date
    08-23-2010
    Location
    uk
    MS-Off Ver
    365 on Mac
    Posts
    146

    Re: How to count occurrence of items occurring both singly or in a string within a ce

    Hi Sweep
    I tried this but it doesn't seem to work. I have a column where there are 1s in some of the cells. None of them are in strings in this case. Using "1*" returns a value of 0; using "1" returns a value of 43, which is correct. There are no multiple occurrences of a value within any cell.

  4. #4
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,444

    Re: How to count occurrence of items occurring both singly or in a string within a ce

    OK,

    So this should do it,

    =COUNTIF(A1:A12,"*1*")+COUNTIF(A1:A12,1)

  5. #5
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: How to count occurrence of items occurring both singly or in a string within a ce

    =SUMPRODUCT(--ISNUMBER(SEARCH("1",A1:A10)))
    =SUMPRODUCT(--ISNUMBER(SEARCH("b",A1:A10)))
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  6. #6
    Forum Contributor
    Join Date
    08-23-2010
    Location
    uk
    MS-Off Ver
    365 on Mac
    Posts
    146

    Re: How to count occurrence of items occurring both singly or in a string within a ce

    That's the ticket, Sweep! Perfect solution. Thanks very much.

+ 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