Count Occurrences of String in Cell Range

I have a column like this:
Header 1
AA
AA, BB
BB
BB, AA
AA
I need to count how many times "AA" appears throughout this column, so in this case the answer should be 4. I've tried searching for hours, but can't find anything. Anyone have any ideas?
Thanks!

Hi G,
COUNTIF, using wildcards can count the number of cells containing the specific string.
The example below shows the results where a cell contains AA more than once. C2 contains the same formula as above. C4 contains =SUM(B). Cells in column B use LEN() and SUBSTITUTE to calculate the number of times AA appears in each row of column A.
A2, and filled down: =(LEN(A2)-LEN(SUBSTITUTE(A2,B$1,"")))/LEN(B$1)
Regards,
Barry

Similar Messages

  • How do I get a 0 to display when a count = 0 (zero)? (The cell is blank)...

    (Running Business Objects Release 2 (Web-I), No other reporting modules)
    How do I get a 0 to display when a count = 0 (zero)? (The cell is blank)...
    In my reports, I count the number of tests of one of our products and another count on the number of failures.  I then use a simple formula to give me the defect rate percentage (DR%)
    The universe objects used in the calculation are:
    Assembly Number (dimension)
    Human Sn (dimension)
    Test Code Description (dimension)
    I created a variable (called [Count Assys]) that counts the number of Assemblies Tested:
    Formula: =Count([Assembly Number];All)
    Another variable (called [Failed Count]) counts the number of failed tests:
    Formula: =Count([Test Code Description];All) Where ([Test Code Description] <> "FUNCTIONAL TESTS PASSED")
    NOTE: There is a "not equal to sign" between [Test Code Description] and "FUNCTIONAL..." above, but the forum is blanking it when I preview the message.  Not a big deal, but it may be important for someone looking to help...
    I then have a third variable called [DR%] that divides [Failed Count] into the number of [Count Assys], which yields a number formatted as a percentage.
    Formula: =[Failed Count]/[Count Assys]
    The above works great! 
    The problem is: when I have a zero defect count (everything passes), the cell is blank, so the percentage variable remains blank.  I want a zero (0) to appear if nothing failed so the percentage appears as 0%
    I've searched this forum completely and have tried several Properties changes and different variable strings (like =If([Failed Count]<1,0) and the cell stays blank and cannot come up with an answer.
    This one seems simple to me, but everything I've tried has yielded zero <smile> results.
    Thanks,
    Charles
    Edited by: Charles Norman on Dec 9, 2008 12:44 PM
    Edited by: Charles Norman on Dec 9, 2008 12:47 PM

    Hi Charles,
    Use [Dr%] Variable formula as =if(IsNull([Dr%]);0;[DR%])
    Here IsNull returns the Boolean value of variable [Dr%] if its true then inserts 0 else the percentage values of failed tests based on the  total number of assembly tests performed.
    I Hope this is what you want to achieve....
    Thanks....
    Pratik

  • Variable Cell Range

    How do I use variables to define a cell range?
    I have a series of data elements that are organized by date. I need to find a list of dates when specific events have occurred (each event is marked by a flag value of 1). I'm using VLOOKUP to find the first date when the event occurs. For the next date I need to adjust the cell range I'm searching so that it won't pick up the first occurence of the flag value (1).
    Example:
    1st query =VLOOKUP(1,G3..G223,51,0)
    The first query returns a date that is in row 12. I now need to make the second query look for rows 13 through 223.
    Overall I need to create over 500 such queries (50 columns of data and 10 events in each row), so typing in each query individually is not an appealing option.
    Thanks!

    Hi Dad,
    I'm having some trouble with your description of the data table. If I read it correctly, the cells in column G contain either a 1 or are empty (or contain a zero). If this is correct, and you are using column G to hold the compare range, then, as the VLOOKUP description in AppleWorks Help states, "If the values in the compare range are not in strict ascending or descending order, or the compare range does not contain an inclusive range from the highest to lowest possible value, the results can be unpredictable." It's very difficult to place the values 0 and 1 into 221 individual cells in "strict ascending order."
    VLOOKUP(v,cr,os,m) looks for a specific value (v) in a strictly ordered list of values (cr), and when that value is found*, returns the value in the cell that is in the same row and offset a specific number of columns (os) to the right.
    *The method of comparison (m) determines whether an exact match is necessary or if the comparison can be <=v or >=v.
    •From the Compare range in your formula, your table has 221 rows (3 through 223). My assumption is that you are recording data for 221 specific dates.
    •From the offset value in the formula (51) the table has 52 columns—a compare range column, a result column, and 50 others between them.
    •From your formula, it appears that only one column of the chart is being used as a compare range for a particular search (event?).
    •You state you have 50 columns of data and that there are 10 events in each row (of 52? cells).
    From the last statement, I infer that there are 50 distinct possible events (one for each column), and that 10 of these 50 events occur on each date. Is that correct?
    If I understand the description, then my impression is that VLOOKUP is not an effective tool for this job.
    Instead, I would suggest a larger table and a set of formulas which will construct a list of the dates on which each event occurs. (Note that the maximum length of a formula, and the maximum length of data for a single cell are both 255 characters. This may necessitate some adjustment to the formulas if one event occurs a great number of times.)
    The larger table will consist of two (or three) sections:
    •a data entry section much like my understanding of your current table. One column will contain a list of dates. Fifty other columns will each represent a single type of event. Each cell in that column will contain a 1 if the event occurred on the date listed in that row, or will be empty if the event did not occur on that date. for illustration purposes, the dates will be listed in F3..F223, and the events in columns G..BD, with the occurence of Event 1 reported in G3..G223.
    •A calculated section which copies the contents of the data block, substituting the correct date for each occurrence of a 1 in the data. In this block (BF3..DC223), column BF will list the dates on which event 1 occurred, column DC the dates on which event 50 occurred. Row 2 (or Rows 1 and 2) in this secton will repeat the headers in the data entry section.
    Formulas:
    BF1: =G1
    Fill this formula Down and Right to DC2
    BF3: =IF(G3=1,=DATETOTEXT($F3),"")
    Fill this formula Down and Right to DC223
    Collecting the dates:
    Open a new Word Processor document.
    For EACH event, switch back to the spreadsheet document, select the full column containing the dates for that event (eg. BF1..BF223 for Event 1) and Copy.
    Switch to the word processor document and Paste, then press shift-return twice (This enters a visual separation that will not be removed in the next step.)
    Save the (temporary) WP document. You will have to name it the first time. After that, just press command-S. (This gives you a fall back if you make—and notice—an error along the way.
    Repeat these three steps until you have transfered all 50 columns of data (including the empty cells in each column) into a single list in the WP document.
    Now use Find/Change to remove all of the empty lines in the list.
    Press command-F to open the Find/Change dialogue.
    Type "\p\p" into Find and "\p" into Change (both without the quotes).
    Repeat the next three steps until AppleWorks reports "0" occurences were changed.
    Click Change All.
    Click OK to acknowledge the warning that this action is irreversible.
    Read the number of changes that occurred, then Click OK to close this alert.
    You will now have a single column list of each event, followed by the dates on which it occurred. If you want to show this list as a table (in a spreadsheet), Select and copy each section Event and dates it occurred) individually, switch to the spreadsheet, click on the cell where you want that column of dates to begin, and Paste. Repeat.
    It may be possible to automate this last part, either through a further section in the spreadsheet, or through the use of an AppleScript to collect and organize the calcualted data.
    Regards,
    Barry

  • Count occurrences of a phrase

    Hi, what is the best way to count occurrences of a phrase (multi-gram words) in a document (corpus)?
    I am using String.split("regular expression here") to split the content of a document. For example to count how many times "this noun phrase" occurs in a document, i do
    String nounSingular = "this noun phrase";
    String nounPlural = "this noun phrases";
    String documentContent="blahblah...";
    int occur = documentContent.split("\\b+"+nounSingluar+"\\b+").length;
    ......But my worry is that regex processing is heavy. So the scalability of this method may be bad over large corpus, and long noun phrase strings.
    Any better ideas please? Using String.indexOf() iteratively?
    Many thanks!

    hey
    so if you use either split, or stringtokenizer, you will not get the correct result. you must use indexOf.
    Why? if you use split and the phrase is at the very start of the string, then you will not get the correct number of occurrences.
    Heres some code that works on a string. can't say much for performance! maybe read your text in line by line..?
              String searchMe = "policy policy bananas is the policy base of all policy";
              int occurs = 0;
              int nextIndex = 0;
              while (true){
                   int test = searchMe.indexOf("policy", nextIndex);
                   if (test == -1){
                        //then there are no occurrences
                        break;
                   } else {
                        //there is an occurrence
                        occurs++;
                        nextIndex = test + 1;
              }try it with split, it doesn't work... go ahead!
    Oh, and my message to the guy who has a go at me for reviving an old thread: People SEARCH and get these threads all the time in Google results. THATS WHY i post. just trying to help everyone...

  • IOS5.0.1 constant error "iPhone can not make or receive calls.  Restore from iTunes":  I get this message and the phone will no longer work (happend once while on airplain mode and now once while in wifi only area, out of cell range).  help!

    All- I get this message ("iPhone can not make or receive calls. Restore from iTunes" (happend once while on airplain mode and now once while in wifi only area, out of cell range)). iPhone 4.  Newest OS.  Never happened with old OS! Cycling phone on/off does not help.  Ignoring message causes phone to cycle off then on.  After first time this happened, I restored.  Six days later...same problem!  Clearly a new fix is necessary.  Suggestions? 

    I have not tried that...I will look up the process so that I can do it correctly (and still transfer all of my files, contacts, etc).  Any suggestions?  What is the advantage of restoring as a new device..is this more akin to a complete wipe of a hard drive?

  • How to get variables queryID and Result Area in AO  same as SAPBEXonRefresh(queryID As String, ResultArea As Range)

    Hi Folks,
    I am migrating some BEX 3.5 workbooks that contain macros into BusinessObjects Analysis workbooks.
    VBA knowledge is rare but I figured out how to call routines after refresh using
    Application.Run("SAPExecuteCommand", "RegisterCallback", "AfterRedisplay", "Callback_AfterRedisplay")
    Now I attempt to copy the SAPBEXonRefresh code into the Sub Callback_AfterRedisplay() but SAP SAPBEXonRefresh
    used queryID and ResultArea as parameters.
    As far as I see these are global SAP variables available in BEX but not available in AO.
    What are the equivalent functions in AO to get those values so that I can use the functions to fill the variable values and the "old" code can run?
    Thanks for all replies in advance,
    Axel

    Hello Axel,
    i am not familiar with the SAPBEXonRefresh sub. From the Parameters i infer that it probably gets called once for every queryID and ResultArea.
    If you register a "Callback_afterRedisplay" macro in Analysis, it does not get called once for every datasource. It gets called only once after a redisplay, regardless of the number of datasources and crosstabs in your workbook.
    Analysis Workbooks have named ranges for the Analysis crosstabs. You should be able to use these for the ResultArea. The named range has a "SAP" put in front of the crosstabs formula alias.
    e. g. in the Analysis Design Panel components tab your crosstab is listed with the formula alias "Crosstab1" the named range would be: "SAPCrosstab1".
    If your own VBA code needs a ResultArea and QueryID Parameter, determine and assign the appropriate values before executing.
    e. g. your workbook has one datasource "DS_1" and one crosstab with formula alias "Crosstab1":
    Sub Callback_AfterRedisplay()
    Dim ResultArea as Excel.Range
    Dim queryID as String
    set ResultArea = ActiveWorkbook.Names("SAPCrosstab1").RefersToRange
    'probably set ResultArea = Range("SAPCrosstab1") might work as well
    queryID = "DS_1" 'or something appropriate to your old code
    Call SAPBEXonRefresh(queryID, ResultArea)
    End Sub
    Sub SAPBEXonRefresh(queryID as String, ResultArea as Range)
    <YourOldCode>
    End Sub
    Adapt the coding in "Callback_AfterRedisplay" to execute the "SAPBEXonRefresh" sub more than once for additional crosstabs and queries.
    Regards,
    Werner

  • Using Bex query through Query Browser - add result set to Cell range?

    Hi all,
    I have up to now used Xcelsius on NW with BICS connection towards BEx queries.
    When I use this connection via Data Manager in Xcelsius, I'm able to use the Cross-table functionality to insert my entire dataset into a cell Range.
    But now I have an requirement to save my Dashboards on the BO server, so I need to go through Query Browser to extract data from SAP BW to my Dashboard.
    When inserting the query in the Query browser and I want to assign the data to Excel ranges, it seems like I need to do this for each individual Infoobject and Key Figure. Since I have many Key Figures (30-50), this is a lenghty process.
    Is there a way to insert the entire dataset from Query into a cell range (both rows and columns), or do I need to do this for each Key Figure as indicated in the screen shot above?
    --> I know that the Query Browser flattens my cross-table from the Query, but still, it should be possible to avoid to input all my Key Figures (30-50) individually to corresponding cells in my Excel part of the Dashboard.
    regards
    Oddmar Lid
    asdfasf

    Hi Oddmar,
    If you want to display the data retrieved from the query you could map the data using the Query data.
    Pull scorecard component (for example) and in properties if you see the Display data click on the dropdown and select Query data.
    Hope this helps !

  • Type in a cell range

    This is probably the worst spreadsheet program in the history of man.  How the **** do you type in cell ranges in this daffy thing?

    fcarlson,
    I am curious... how would you expect to enter a formula?
    Numbers is definitely light weight in many areas, no doubt.  You can provide feedback, if you care to, by selecting the menu item "Numbers > Provide Numbers Feedback"
    I do disagree with your statement "This program is totally ********. "  solely because you paid $0 for it.  There are other free programs like LibreOffice that are more excel-like.  Keep trying Numbers you may like it I say.  you could try it in a box with a fox.  In a house with a mouse.

  • Creating "the token representing the cell range"?

    Reference: http://help.apple.com/numbers/mac/3.2/#/tan727173a8, "Preserve row or column addresses in formulas".
    "Click the triangle on the token representing the cell range you want to preserve.
    " - end of quote.
    Where in this help manual can I find where to call a cell range "Number of Guests"?
    All the other token references are about cell formats.

    Mel,
    select the range of cells:
    The range "token" is the blue, rounded, highlighted text "C2:C10".  The triangle you should click is just to the right of this text.

  • Single Cell Copy to Cell Range

    If I create a cell value/formula, then copy that cell, select a range of cells, and paste, in Excel it copies the source cell contents to all cells in the range (adjusting relative references in a formula). In Numbers, it copies only to one cell in the range. Having to paste one cell at a time is agonizing, and this operation is something I do all the time in editing an existing spreadsheet.
    The only alternative I see is to copy one cell to two, then select a two-cell range to copy and paste etc in geometric progression. Is there something simple I'm missing?

    I did a search in the help for "fill" & got this:
    Here are ways to autofill table cells:
    To paste the content and fill of a cell into adjacent cells, select the cell and then drag the Fill handle in its lower right corner over the cells into which you want to paste. You can drag to the right to add values to adjacent cells in the same row, or you can drag down to add values to adjacent cells in the same column.
    Any data, cell format, formula, or fill associated with the selected cell is pasted, but comments aren’t pasted.
    If the selected cell contains no data, autofilling clears data from target cells.
    You can also add values to cells based on value patterns. For example, if a cell contains a day of the week or a month, you can select the cell and then drag to the right or down to add the next day of the week or month to the adjacent cell.
    To create new values based on numeric patterns, select two or more cells before dragging. For example, if two selected cells contain 1 and 2, the values 3 and 4 are added when you drag through the adjacent two cells. And if two selected cells contain 1 and 4, the values 7 and 10 are added when you drag through the adjacent two cells (values are incremented by 3).
    This is similar to how I've done fill down or fill right in AppleWorks, so I think the relative references would copy.

  • Working with strings and cell references

    Hi all,
    I'm a fairly new user to the Mac world but I'm a power user of Excel trying to moving into the number environment. I'm currently experiencing some very inconsistent behaviour working with text strings in Numbers.
    I've used both '&' and CONCATENATE to try to concatenate strings and cell references and regualarly I'm getting the situation where the formula initially works and then when I save and reopen the file the cells containing the error return a syntax error.
    Upon examining the formula it appears that the cell references are converted from cell references to simple text so & (b2) & becomes &b2&.
    Any ideas what is causing this?

    I apoligise for this tardy response. Firstly, the issue occurred not when I first create the formula but when I save, close and reopen the document.
    Upon examining the formula, the cell reference is not being recognised and so instead of A2 referencing a cell it's simple A2 which causes an error.
    And this is happening in more than one cell (whole rows of cells actually as I've often created a formula and copied it down 10 or 200 rows).
    It is also happening on more than one file Badunit so I don't think it's a corrupt file.
    It's more than a little annoying though as it means every few days when I go back in to a file I need to spend a few minutes recreating the formulas.
    Any other suggestions?
    Oh and I've tried both methods of formula creation of typing the reference and clicking, but the result is the same.
    Message was edited by: Un-decided

  • Count integers in String array

    String[] s= {"xx","yy","34","35","46"};
    i want to count the integers in that String array.
    output: 3
    Can any one suggest me how to get that one.

    Try it again with this String in your
    array:"2147483648"
    Ok if you have to account for very large integers then you could use the following:
    String[] array = {"xx","yy","34","35","46", "2147483648"};
    int count = 0;
    for (String s : array) {
         boolean numericOnly = true;
         for (char c : s.toCharArray()) {
              if (c >= 48 && c <= 57) {
                   // Int value
              else {
                   numericOnly = false;
         if (numericOnly)
              count++;
    System.out.println("" + count);

  • How can  parse this xml tag " Cell ID="0" Type="String" Afghanistan cell "

    Hi,
    I have to parse this type of xml file.
    so how can i parse this type of xml file like
    <Row ID="1">
    <Cell ID="0" Type="String" >Afghanistan</Cell>
    <Cell ID="1" Type="Number" >93</Cell>
    <Cell ID="2" Type="Number" >0</Cell>
    <Cell ID="3" Type="Number" >1</Cell>
    </Row>

    You haven't given us enough information. Is this for iPhone or Mac OS X? What language are you using? etc.

  • Count occurrences of matched words

    All,
    Does anyone know the syntax or algorithm to count the occurrences of matched words that where compared from two separate columns or tables? Below is a simple example of the type of comparison I would like to perform. I found the function regexp_count, but it only works in 11g. Unfortunately, I have Oracle 10g. Any help would be greatly appreciated. Thanks
    i.e.
    drop table compare_matched_words;
    create table compare_matched_words (
    query_id number,
    query_string1 varchar2(80),
    query_string2 varchar2(80)
    insert into compare_matched_words values (1, 'oracle 255','oracle1 255');
    insert into compare_matched_words values (2, 'larry or ellison','larry or');
    insert into compare_matched_words values (3, 'oracle and text','and');
    insert into compare_matched_words values (4, 'market1 share','market share');
    insert into compare_matched_words values (5, 'larry or',' larry or ellison');
    insert into compare_matched_words values (6, 'oracle1 255','oracle 255');

    Issue is not in 11g. Before you can solve the task you need to split QUERY_STRING1 and QUERY_STRING2 into words and then compare words for same QUERY_ID. To split string into words use something like:
    select  query_id,
            regexp_substr(query_string1,'\w+',1,column_value) query_string1_word
      from  compare_matched_words t,
            table(
                  cast(
                       multiset(
                                select  level
                                  from  dual
                                  connect by level <= length(regexp_replace(regexp_replace(QUERY_STRING1,'\w+','A'),'[^A]'))
                               ) as sys.OdciNumberList
    SQL> /
               QUERY_ID QUERY_STRING1_WORD
                      1 oracle
                      1 255
                      2 larry
                      2 or
                      2 ellison
                      3 oracle
                      3 and
                      3 text
                      4 market1
                      4 share
                      5 larry
               QUERY_ID QUERY_STRING1_WORD
                      5 or
                      6 oracle1
                      6 255
    14 rows selected.
    SQL> Now:
    select  t1.query_id,
            t1.query_string1,
            t2.query_string2,
            count(*) matchin_word_count
      from  (
             select  query_id,
                     query_string1,
                     regexp_substr(query_string1,'\w+',1,column_value) query_string1_word
               from  compare_matched_words t,
                     table(
                           cast(
                                multiset(
                                         select  level
                                            from  dual
                                           connect by level <= length(regexp_replace(regexp_replace(query_string1,'\w+','A'),'[^A]'))
                                        ) as sys.OdciNumberList
            ) t1,
             select  query_id,
                     query_string2,
                     regexp_substr(query_string2,'\w+',1,column_value) query_string2_word
               from  compare_matched_words t,
                     table(
                           cast(
                                multiset(
                                         select  level
                                            from  dual
                                           connect by level <= length(regexp_replace(regexp_replace(query_string2,'\w+','A'),'[^A]'))
                                        ) as sys.OdciNumberList
            ) t2
      where t2.query_id = t1.query_id
        and t2.query_string2_word = t1.query_string1_word
      group by t1.query_id,
               t1.query_string1,
               t2.query_string2
      order by t1.query_id
               QUERY_ID QUERY_STRING1                  QUERY_STRING2                   MATCHIN_WORD_COUNT
                      1 oracle 255                     oracle1 255                                      1
                      2 larry or ellison               larry or                                         2
                      3 oracle and text                and                                              1
                      4 market1 share                  market share                                     1
                      5 larry or                        larry or ellison                                2
                      6 oracle1 255                    oracle 255                                       1
    6 rows selected.
    SQL> SY.

  • How can i count the word in a cell.

    Dear Experts,
    i want to count the word in cell how can i do this ?
    Isthere any function ?
    plz give logic or command.

    You can ty :
    SQL> var text varchar2(50)
    SQL> exec :text := 'How do I count the number of words in my cell?'
    PL/SQL procedure successfully completed.
    SQL> select text,
      2         sum(case when substr(text,rownum,1)=' '
      3                       and substr(text,rownum-1,1)!=' '
      4                  then 1
      5                  else 0 end) nb_word
      6  from (select rownum,:text||' ' text,length(:text) ln from dual)
      7  connect by level <= ln+1
      8  group by text
      9  /
    TEXT
       NB_WORD
    How do I count the number of words in my cell?
            11
    SQL>  exec :text := 'How     do I count the number of words in my   cell?    '
    BEGIN :text := 'How     do I count the number of words in my   cell?    '; END;
    ERROR at line 1:
    ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    ORA-06512: at line 1
    SQL> var text varchar2(1000)
    SQL> exec :text := 'How     do I count the number of words in my   cell?    '
    PL/SQL procedure successfully completed.
    SQL> select text,
      2         sum(case when substr(text,rownum,1)=' '
      3                       and substr(text,rownum-1,1)!=' '
      4                  then 1
      5                  else 0 end) nb_word
      6  from (select rownum,:text||' ' text,length(:text) ln from dual)
      7  connect by level <= ln+1
      8  group by text
      9  /
    TEXT
       NB_WORD
    How     do I count the number of words in my   cell?
            11
    SQL> select * from v$version where rownum=1;
    BANNER
    Oracle9i Enterprise Edition Release 9.2.0.7.0 - Production
    SQL> Nicolas.
    Well, we can discuss about what limit a word : here space, but there is point, double-point, and so on... And about what is a word : do the punctuation is a word ?
    For example :
    "It's a word !"=>how many words are in this sentence ?
    http://en.wikipedia.org/wiki/Word
    Message was edited by:
    N. Gasparotto

Maybe you are looking for