We often have negative numbers in our Excel dataset. Negative numbers can create a problem while calculating in Excel. So, it is important to count the negative numbers present in a dataset. In this article, we will discuss how to count negative numbers in Excel.
Download the Practice Workbook
3 Handy Approaches to Count Negative Numbers in Excel
In this blog, we will discuss 3 effective methods to count negative numbers in Excel. In the first method, we will use the COUNTIF function to count the negative numbers. Next, we will opt for the SUMPRODUCT function to do the task. Finally, we will use a VBA code to do our calculation. We will use the following sample dataset to carry out our method illustrations.
1. Using COUNTIF Function to Count Negative Numbers in Excel
In this method, we will use the COUNTIF function to count the negative numbers. Follow the subsequent steps to carry out the task.
- Firstly, choose the cell in which to display the outcome of the count of the negative numbers.
- In this instance, the cell is G5.
- Then, write the following formula in cell G5.
- Here, E5:E10 is the range of cells where you want to search for the negative numbers.
- “<0” or “less than zero” is the condition on which the function will return the result.
- This function returns an array of True and False.
- To convert those True and False into numbers 0 and 1, we will use the two negative signs at the beginning of the function.
- Finally, hit Enter.
- As a result, the cell will display the quantity of negative numbers in the chosen cell range.
- In our case, the result is 2.
2. Applying SUMPRODUCT Function to Count Negative Numbers
In this example, we will opt for the SUMPRODUCT function to count the negative numbers. Follow the ensuing steps to do it.
- Firstly, decide which cell will contain the results of the count of the negative numbers.
- In this instance, we will select the G5 cell.
- After that, enter the following formula into cell G5.
- In this case, the range of cells where you want to look for the negative numbers is E5:E10.
- The condition on which the function will return the result is “0” or “less than zero“.
- Lastly, press Enter.
- Consequently, the cell will return the number of negative numbers in the selected range of cells.
- In our case, the result is 2.
3. Applying VBA Code to Count Negative Numbers in Excel
In this method, we will resort to a VBA code to count the numbers of the negative numbers in our dataset. Adhere to the outlined steps below to complete the task.
- Firstly, select the range of cells where you want to look for the negative numbers.
- In our case, the range is E5:E10.
- Secondly, go to the Developer tab.
- From the Developer tab, select the Visual Basic command.
- Consequently, a Visual Basic dialogue box will appear.
- Thirdly, in the Visual Basic tab, click on Insert.
- Then, select the Module option.
- Consequently, a coding Module will appear.
- In the coding module, write down the following code.
- Then, save the code.
Sub Counting_negative_numbers() 'declaring variable' Dim cell_rng As Range 'setting value for the variable' Set cell_rng = Application.Selection 'applying the COUNTIF function' Cells(5,6).Value = Application.WorksheetFunction.CountIf(cell_rng, "<0") End Sub
VBA Code Breakdown
- Dim cell_rng As Range: Here, we will declare the variable as Range type variable.
- Set cell_rng = Application.Selection: This implies that the cell_range variable will be assigned the value of the selected range of cells.
- Cells(5,6).Value = Application.WorksheetFunction.CountIf(cell_rng, “<0”): This means, the COUNTIF function will go through the values of the cell_rng variable which is in this case the values in the selected range of cells. The function will impose its condition which is all values that are less than zero in all the cells and return the number of values which satisfies the condition.
- Finally, go to the Run tab and click on it.
- From the drop-down option, select the Run command to run the code.
- As a result, you will find that Excel will return the number of negative numbers from the selected range.
- In this instance, the result is 2.
Negative numbers in a dataset could be a tricky business. So, Excel users need to keep track of the negative numbers. The users can easily do that by counting the negative numbers. After going through this article, the readers will have three effective methods to count the negative numbers in their dataset. Please feel free to leave a comment if you have any queries or recommendations for improving the article’s quality. To learn more about Excel, you can visit our website, ExcelDemy. Happy Learning!
- How to Add Brackets to Negative Numbers in Excel (3 Easy Ways)
- How to Change Positive Numbers to Negative in Excel (6 Ways)
- How to Apply Formula for Positive and Negative Numbers in Excel
- [Fixed!] Excel Not Adding Negative Numbers Correctly (4 Solutions)
- Excel Negative Numbers in Brackets and Red (2 Examples)