Skip to main content

Using the CountIF Function in Microsoft Excel

  - The next Conditional function we're going to use is CountIF. This one is fairly straightforward. It looks at a range of cells and tells you how many of them meet the criteria that you set. Once again, we'll use the student exam marks spreadsheet.

Copying and Pasting Data to a new Sheet

Open up the Spreadsheet you used for the last section. (If you haven't yet downloaded the spreadsheet, click here: Download the spreadsheet.)
Because the exam spreadsheet might be a little full, we'll start on a new sheet. We'll copy and paste the student data onto sheet 2. To do that, follow these steps:
  • Highlight the data you want to copy
  • For us, that's the student data, as in the image below:
Highlight the data in your spreadsheet
  • With the data highlighted, click on Edit from the menu bar
  • From the drop down list, click on Copy. The marching ants surround your highlighted data
  • Look at the bottom of the spreadsheet and locate Sheet2, as in the next image:
Click on Sheet2
  • Click on Sheet2 with your left mouse button
  • The blank Sheet2 spreadsheet should appear
  • Click inside cell A1
  • Press the Return key on your keyboard to paste the data (Or click Edit > Paste from the Excel menu bar)
Add the following labels to Sheet2 of your spreadsheet:
We'll now use the CountIF function to see how many of the students were above a score of 70 in each subject.

CountIF
The CountIf function only calculates things when a certain condition is met. For example, only count the students whose grades are above B.
The CountIF function uses this syntax:
COUNTIF(rangecriteria)
In other words, it takes two arguments. The first argument is range, and this means the range of cells you want to count. The criteria is what you want excel to look for when it is counting. Let's see it in action.
  • Click inside cell B15
  • Click inside the formula bar
  • Enter the following function:
=CountIf(B2:I2">= 70")
  • Press the return key on your keyboard
  • The answer you should have got was 4
The formula says, look in cells B2 to I2. Then check for a score of greater than or equal to 70. If you find this score, keep a Count.
So 4 students achieved a mark of 70 or above for Maths. To do the rest of the scores, you can use AutoFill. When you have finished, it should look like this one below:
CountIF is a very useful function for simple data analysis.

In the next part, we'll take a look at two more useful functions: AND and SUMIF.

Comments

Popular posts from this blog

Beginners PHP  -This is a complete and free PHP programming course for beginners. It's assumed that you already have some HTML skills. But you don't need to be a guru, by any means. If you need a refresher on HTML, then click the link for the Web Design course on the left of this page. Everything you need to get started with this PHP course is set out in section one below. Good luck! Home Page > PHP Section One - An Introduction to PHP 1. What is PHP and Why do I need it? 2. What you need to get started 3. Installing and testing Wampserver 4. Troubleshooting > PHP Two - Getting Started With Variables 1. What is a Variable? 2. Putting text into variables 3. Variables - some practice 4. More variable practice 5. Joining direct text and variable data 6. Adding up in PHP 7. Subtraction 8. Multiplication 9. Division 10. Floating point numbers > PHP Three - Conditional Logic 1. If Statements 2. Using If Statements 3....
Visual Basic .NET Contents Page   -This computer course is an introduction to Visual Basic.NET programming for beginners. This course assumes that you have no programming experience whatsoever. It's a lot easier than you think, and can be a very rewarding hobby! You don't need to buy any software for this course! You can use the new FREE Visual Basic Express Edition from Microsoft. To see which version you need, click below: Getting the free Visual Studio Express - Which version do I need? > VB .NET One - Getting Started   1. Getting started with VB.NET 2. Visual Basic .NET Forms 3. Adding Controls using the Toolbox Home Page 4. Adding a Textbox to the Form 5. Visual Basic .NET and Properties 6. The Text Property 7. Adding a splash of colour 8. Saving your work 9. Create a New Project >   VB .NET Two - Write your first .NET code   1. What is a Variable? 2. Add a coding button to the Form 3. Writing y...
The Excel SumIF Function  - Another useful Excel function is SumIF. This function is like CountIf, except it adds one more argument: SUMIF( range ,  criteria ,  sum_range ) Range and criteria are the same as with  CountIF  - the range of cells to search, and what you want Excel to look for. The Sum_Range is like range, but it searches a new range of cells. To clarify all that, here's what we'll use SumIF for. (Start a new spreadsheet for this.) Five people have ordered goods from us. Some have paid us, but some haven't. The five people are Elisa, Kelly, Steven, Euan, and Holly. We'll use SumIF to calculate how much in total has been paid to us, and how much is still owed. So in Column A, enter the names: In Column B enter how much each person owes: In Column C, enter TRUE or FALSE values. TRUE means they have paid up, and FALSE means they haven't: Add two more labels: Total Paid, and Still Owed. Your spreadsheet should look something li...