Microsoft Excel - count occurrences

Asked By Randall Lloyd
30-Dec-10 12:41 AM
I am tracking professional certifications of 200 hundred members on my program.  The principle condition I track is whether their certs (and each person may have many) are current or expired.  Row 1 are just column headers.  There are more than 30 possible certifications and each cert has three columns devoted to it: 1) Assoc, 2) Earn Date, and 3) Expiration Date.  With 30 possible certs  I want to determine if a worker has (in this case) no certs.

I could use help with a formula that will count the occurrences in the row that correspond to part of the text string in the column headers.  For example, count all occurrences of a date in the row where the text string "Expiration Date" is in the corresponding header.

Thanks for the help.  Randy





  olvin j replied to Randall Lloyd
30-Dec-10 12:53 AM
hi,


Count Cells with Numbers -- Excel COUNT

The Excel COUNT function will count cells that contain numbers. Its syntax is:
    =COUNT(value1, value2,...value30).
The arguments (e.g. value1) can be cell references, or values typed into the Excel COUNT formula.

The following Excel COUNT function example uses one argument -- a reference to cells A1:A5.

  1. Enter the sample data on your worksheet
  2. In cell A7, enter an Excel COUNT formula, to count the numbers in column A:   =COUNT(A1:A5)  
  3. Press the Enter key, to complete the formula.
  4. The result will be 3, the number of cells that contain numbers.
    Cell A1 isn't counted, because it contains text.

Note: Since dates are stored as numbers, the Excel COUNT function will include any cells that contain dates.

View the steps in a short Excel Count Functions video 
(COUNT, COUNTA, COUNTBLANK)  

Count Cells with Data -- COUNTA

The COUNTA function will count cells that are not empty. Its syntax is:
    =COUNTA(value1, value2,...value30).
The arguments (e.g. value1) can be cell references, or values typed into the formula. The following example uses one argument -- a reference to cells A1:A5.

  1. Enter the sample data on your worksheet
  2. In cell A7, enter a COUNTA formula, to count the numbers in column A:   =COUNTA(A1:A5)  
  3. Press the Enter key, to complete the formula.
  4. The result will be 4, the number of cells that contain data.

    Note: COUNTA will count cells with formulas — including those that look empty, because they evaluate to "", e.g. =IF(B2="","",B2). It will also count cells which had formulas that evaluated to "", but then were converted to values (Edit | Paste Special, Values). You can see apostrophes in those "non-blank" converted cells, if you add a check mark to Tools | Options, Transition tab, "Transition navigation keys."

View the steps in a short Excel Count Functions video 
(COUNT, COUNTA, COUNTBLANK)  

  

Excel Count Text

=COUNTA(A1:A5)

Count Blank Cells -- COUNTBLANK

The COUNTBLANK function will count cells that are empty. Its syntax is:
    =COUNTBLANK(range).
The following example uses a reference to cells A1:A5.

  1. Enter the sample data on your worksheet
  2. In cell A7, enter a COUNTBLANK formula, to count the numbers in column A:   =COUNTBLANK(A1:A5)  
  3. Press the Enter key, to complete the formula.
  4. The result will be 1, the number of empty cells.

    Note: COUNTBLANK will count cells with formulas — including those that look empty, because they evaluate to "", e.g. =IF(B2="","",B2). It will also count cells which had formulas that evaluated to "", but then were converted to values (Edit | Paste Special, Values). You can see apostrophes in those "non-blank" converted cells, if you add a check mark to Tools | Options, Transition tab, "Transition navigation keys." 

View the steps in a short Excel Count Functions video 
(COUNT, COUNTA, COUNTBLANK)  

Excel Count blanks

=COUNTBLANK(A1:A5)

Count cells that match criteria -- COUNTIF

Match criterion exactly

In Excel, count cells that meet a specific criterion. In this example only the Pen orders will be counted.

  1. Select the cell in which you want to see the count (cell A12 in this example)
  2. Type an equal sign (=) to start the formula
  3. Type:   COUNTIF(
  4. Select the cells that contain the values to check for the criterion. In this example, cells A1:A10 will be checked
  5. Type a comma, to separate the arguments
  6. Type the criterion. In this example, you're checking for text, so type the word in double quotes:   "Pen"
    Note: upper and lower case are treated equally
  7. Type a closing bracket
    The completed formula is: =COUNTIF(A1:A10,"Pen")
  8. Press the Enter key to complete the entry
  9. The result will be 4, the number of cells that contain "Pen"

View the steps in a short Excel COUNTIF Match Text Function video 

Count Excel criteria

Match criterion in a string

In Excel, count cells that contain a criterion as part of the cell's contents. In this example all Pen, Gel Pen, and Pencil orders will be counted, because they contain the string "pen".

  1. Select the cell in which you want to see the count (cell A12 in this example)
  2. Type an equal sign (=) to start the formula
  3. Type:   COUNTIF(
  4. Select the cells that contain the values to check for the criterion. In this example, cells A1:A10 will be checked
  5. Type a comma, to separate the arguments
  6. Type the criterion. In this example, you're checking for text, so type the word in double quotes, with one or more asterisk (*) wildcard characters:   "*Pen*"
    Note: upper and lower case are treated equally
  7. Type a closing bracket
    The completed formula is: =COUNTIF(A1:A10,"*Pen*")
  8. Press the Enter key to complete the entry
  9. The result will be 6, the number of cells that contain the string, "Pen"

Note: Instead of typing the criterion in a formula, you can refer to a cell. For example, the formula in step 7 above could be changed to:
    =COUNTIF(A1:A10,"*" & B12 & "*")
if cell B12 contained the text — pen.

View the steps in a short Excel COUNTIF Match Text Function video 

Criterion and operator

You can use an operator with a criterion. In this example only the rows where the quantity is greater than or equal to ten will be counted.

  1. Select the cell in which you want to see the count (cell A12 in this example)
  2. Type an equal sign (=) to start the formula
  3. Type:   COUNTIF(
  4. Select the cells that contain the values to check for the criterion. In this example, cells B1:B10 will be checked
  5. Type a comma, to separate the arguments
  6. Type the criterion. In this example, you're checking for rows where the quantity is greater than or equal to 10. The >= operator is used before the number, and the entire criterion is enclosed in double quotes: ">=10"
    Note: Even though this is a numerical criterion, it must enclosed in double quote marks.
  7. Type a closing bracket
  8. The completed formula is:
          =COUNTIF(B1:B10,">=10")
  9. Press the Enter key to complete the entry

Note: Instead of typing the criterion in a formula, you can refer to a cell. For example, the formula in step 8 above could be changed to:
    =COUNTIF(B1:B10,">=" & B12)
if cell B12 contained the number — 10

Or, you could use a function as part of the criterion. For example: 
    =COUNTIF(A1:A10,"<"&TODAY()) 

Excel COUNTIF Function Using Operator video 

 

Count Excel criteria operator

Match criteria in a range

You can combine COUNTIF formulas, to count rows that are within a range of values. In this example, the formula will count rows where the quantity is between 5 and 10 (inclusive).

  1. Select the cell in which you want to see the count (cell A12 in this example)
  2. Type a formula to count rows greater than or equal to 5:
          =COUNTIF(B1:B10,">=5")
  3. Type a minus sign
  4. Type a formula to count rows greater than 10:
          COUNTIF(B1:B10,">10")
  5. The completed formula is:
    =COUNTIF(B1:B10,">=5")-COUNTIF(B1:B10,">10")
  6. Press the Enter key to complete the entry

Note: Instead of typing the criterion in a formula, you can refer to a cell. For example, the formula in step 8 above could be changed to:
    =COUNTIF(B1:B10,">=" & B12) -
        COUNTIF(B1:B10,">" & C12)
if cell B12 contained the number — 5 and cell C12 contained the number — 10

 

Count cells that match multiple criteria -- SUMPRODUCT

Match multiple criteria

In Excel, count rows that meet two or more criteria. In this example only the rows where the item is "Pen" and the quantity is greater than or equal to ten will be counted.

 

  1. Select the cell in which you want to see the total
  2. Type an equal sign (=) to start the formula
  3. Type:   SUMPRODUCT(--(
  4. Select the cells that contain the values to check for the first criterion. In this example, cells A2:A10 will be checked
  5. Type the first criterion:   ="Pen"
    Note: Because this is a text criterion, it is enclosed in double quote marks.
  6. Type ),--(
  7. Select the cells that contain the values to check for the second criterion. In this example, cells B2:B10 will be checked
  8. Type the second criterion:   >=10
    Note: Because this is a numerical criterion, it isn't enclosed in double quote marks.
  9. Finish with closing brackets: ))
  10. The completed formula is shown at right.
  11. Press the Enter key to complete the entry

Note: Instead of typing the criterion in a formula, you can refer to a cell, as shown in the second formula at right

Excel Count multiple criteria

Use typed criteria:
=SUMPRODUCT(--(A2:A10="Pen"),--(B2:B10>=10))

or cell references:
=SUMPRODUCT(--(A2:A10=D2),--(B2:B10>=E2))

 

Count Rows in a Filtered List -- SUBTOTAL

After you filter the rows in a list, you can use the SUBTOTAL function to count the visible rows.

  1. Apply an AutoFilter to the table. There are instructions here -- AutoFilter Basics
  2. Filter at least one of the columns in the table. In this example, the first column has been filtered for Binders.
  3. Select the cell immediately below the column you want to sum.
  4. Click the AutoSum button on the Excel's Standard toolbar.
    • If you want the SUBTOTAL function in a cell other than the one directly below the filtered list, you can type the formula, instead of using the AutoSum button.
  5. A SUBTOTAL formula will be automatically inserted, totalling the visible cells in the column
    • The first argument in the SUBTOTAL function is a function number, that specifies how the numbers should be calculated. The default is 9, which tells Excel to SUM the numbers.
    • Other function numbers can be used, such as 1 for AVERAGE, and 3 for COUNTA. Look in Excel's Help for a complete list.
  6. To Count all the non-empty cells in column D, use a 3 as the first argument:
    =SUBTOTAL(3,D2:D10)
  7. Press the Enter key to complete the formula entry.

    Note: In Excel 2003, you can use the formula:
      =SUBTOTAL(103,D2:D10)
    to subtotal rows which have been manually hidden, or filtered.

 

=SUBTOTAL(3,D2:D10)

Count Visible Items in a Filtered List

Laurent Longre created a formula that lets you work with visible rows after a filter. For information see, Power Formula Technique in this article at John Walkenbach's web site:
      http://j-walk.com/ss/excel/eee/eee001.txt

Incorporating that technique, SUMPRODUCT can be used to count visible items in a filtered table. In the following example, column D has been filtered for amounts greater than 100. The following formula will count the number of visible rows that contain "Pen" in column A.

  1. From the dropdown list in cell D1, select Custom.
  2. Filter for rows greater than 100.
  3. In cell A12, type: Pen
  4. In cell B12, enter the following formula:

 

Count Excel filtered

=SUMPRODUCT(SUBTOTAL(3,OFFSET(A1:A10,ROW(A1:A10)
        -MIN(ROW(A1:A10)),,1)), --(A1:A10=A12))

  1. Press the Enter key to complete the formula entry.

  Jackpot . replied to Randall Lloyd
30-Dec-10 03:19 AM
Hi Randall

Try the below in cell I2 and copy down as reqired.

=SUMPRODUCT(((ISNUMBER(SEARCH("Exp",$B$1:$H$1))*(B2:H2>0))))

modify the column range to suit 30*3 which is 90 columns...
  Randall Lloyd replied to Jackpot .
04-Jan-11 03:23 PM
Thanks for the formula.  I plugged it in and it works perfectly for the row 2, immediately below the header, but not for subsequent rows.  Rows 3-500 report the number of occurences of "Expiration Date" in the range AL to CV, regardless if they're empty . 

I'm having a problem with the formula in Q2.  I took for formula in R2 and changed the operator from < to >=.  HDemo 8570 records zip.zipowever, it, too, reports the number of occurences of "Expiration Date".

I stripped off the personnel names and uploaded the sheet for your reference.  Can you help again?

Thanks

Randy
  Jackpot . replied to Randall Lloyd
04-Jan-11 08:31 PM
Hi Randall

There is nothing wrong with the formula..Since your date cells contain formulas; I have added one more criteria to the formula to check whether the date fields contain any numerics...Try the below and feedback

=SUMPRODUCT((ISNUMBER(SEARCH("Expiration Date",$AI$1:$CV$1)))*(ISNUMBER(AI2:CV2))*(AI2:CV2>TODAY()))

=SUMPRODUCT(((ISNUMBER(SEARCH("Expiration Date",$AK$1:$CV$1))*(ISNUMBER(AK2:CV2))*($AK2:$CV2<TODAY()))))
  Randall Lloyd replied to Jackpot .
04-Jan-11 08:57 PM
Thanks for the quick reply.  I didn't think of using the second ISNUMBER, but will try it tomorrow when back in the office.

I'll let you know how it goes.

RL
  Randall Lloyd replied to Jackpot .
12-Jan-11 09:36 PM
The formulas worked great, thanks again.  The types and quantity of data that I will have to reference has increased.  To make the newly added data references, instead of making a hundred extra columns, is it possible to reference a table containing the data?  That way, if the data changes, it's easier and safer to make the change in the table and not have to change a formula residing in the sheet.
  Jackpot . replied to Randall Lloyd
12-Jan-11 10:40 PM
Hi Randall

Ofcourse you can..Suppose your table is named table1 try this formula in row 2 and copy down as required

=SUMPRODUCT((ISNUMBER(SEARCH("Expiration Date",Table1[#Headers])))*
(ISNUMBER(Table1[@]))*(Table1[@]>TODAY()))


Table1[#Headers] refers to the header of the table
Table1[@] refers to the current row of the table

  Randall Lloyd replied to Jackpot .
24-Jan-11 05:06 PM

Hi Jackpot,

Thanks for the formula suggestions.  Unfortunately, I misspoke: I meant to say Named Ranges, not Tables.  Even so, I still couldn’t get the formula to work on this most important part of the sheet.  I could use your help yet again.

I’ve included an updated sheet again for your reference.

DI2:HD2 list Computing Environments (CE), as listed in named range (CE) on sheet CEs & Certs .  I made room for 50 Certs, although no one will likely ever need more than 10.  Next to each Cert (starting with DJ2) is a cell reporting Yes or No compliance; this is the problem.  This needs to answer Yes or No, based on the info in the accompanying blue cells HE2:IL2.  Compliance is determined by:

1)    Does the CE have an earned certification in the blue cells, indicated by Yes or Alt method?

2)    Does the CE meet the government’s time requirements?

Each person must list their CEs in the order of importance to their job.  Some people have only one, some have many.  But they need not all be earned at once in order to be compliant.  Each person has 6 months to earn each, starting from the date in column O2.  So CE #1 must be earned within 6 months after the date in O2, CE #2 within 12 months after the date, etc.  If that time period has not yet passed, then compliance is “Yes”.  If the date in O2 is < Today(), AND the blue cells don’t answer Yes or Alt method, then compliance is not met and the cell DJ2 should answer “No”.  Knowing that the govt can change the time interval requirement I made a user-defined variable in K3 on sheet Refs & Defs.  The formula in DJ2 should also reference this so that any future changes to the time requirement can be made globally, without having to edit a formula.

Having said all that, I still feel my huge formula-based approach is less than elegant, and that references to the named ranges would be better.  Do you have time to take a crack at this one?  I thought about using the Index-Match combination but wasn’t sure what to expect when using it “horizontally”, when I’ve always used it for to search within vertical lists.  And if you haven’t yet noticed, I added the names of the CEs (Green cells) to the top of the certs (Blue cells) so I could make the connection.  And because some of the cert titles had the same name as the CE, I added a coma after each CE and added that to the Isnumber (search(DI2&”,”,HE1:IL1).  That may help but the formula still doesn’t work.

The named ranges for the Computing Environments (CE), the corresponding certs (CE Certs), and the answer to certs earned (CE Cert or Training) are all located on sheet CEs & Certs.

Randall Lloyd 



My_new_8570_records-a3-temp.xlsx.zip 

Create New Account
help
Countif Excel = COUNTIF($CF3:$CF1000, "<2000") How can I get this to return the total count excluding the hidden cells in the range? Right now it shows all. - - Thank you! Excel Programming Discussions ActiveSheet.ShowAllData (1) ListObjects (1) AutoFilter (1) ActiveSheet.ListObjects (1) Intersect (1) Sheets 1) Excel (1) ISNUMBER (1) Excel does not provide that function, but John Walkenbach does. Put this in your public code first enter the formula and whenever you edit it later. If you do this properly, Excel will display the formula enclosed in curly braces { }. You do not type in the braces - - Excel puts them in automatically. The formula will not work properly if you do not enter
How do I get started using the Countif, Countifs option with Excel Excel Excel Worksheet Discussions Microsoft Excel (1) Excel (1) COUNTIF (1) MathurMicrosoft (1) Ryan (1) Bliengme (1) Columne (1) Caps (1) In A1:A10, enter
Filter in Microsoft Excel Excel Hi all, I am using microsoft excel 2000. I need help in filtering the data. I have two columns as below Name follows. b How we will define this filter. Please help me. . . . Thanx for reading. Robin Excel Worksheet Discussions Microsoft Excel (1) SUMPRODUCT (1) COUNTIF (1) OFFSET (1) COLUMN (1) VBA (1) À´ªàµà´¤àµ
microsoft excel Excel hi i have 200 tracking numbers a lot of them are repetitive how to i filter them out Excel Worksheet Discussions COUNTIF (1) Debra Dalgleish explains how here: http: / / www.contextures.com / xladvfilter01.html Scroll down to Filter Unique Records. Hope this helps. Pete r In B2: = COUNTIF(A$2:A2, A2)> 1 copy down Auto Filter all the TRUE values keywords: microsoft, excel description: hi i have 200 tracking numbers a lot of them are repetitive how to
Using the Question Mark With COUNTIF Excel Excel 2007 I have a small table that shows me the status of each item on the list. The status can be "Y", "N", "NA", or "?". I am using the COUNTIF function to tell me how many of each status is on the list. For items fine. However, I am curious as to whether or not the "?" can be used with COUNTIF. I have tried the following: = COUNTIF(D11:D33, " = ?") Figuring that the question mark is a special character and that a special syntax might be needed in order make Excel interpret it literally, I have played around with different variations using single and double quotes I have been unable to make the formula work. Is it possible to use "?" with COUNTIF, and if so what is the correct syntax? Thanks for any help that you can