Excel formula for Beginners – How to Count rows that contain specific values in Excel

Hits: 16



(Excel examples for Beginners)

In this end-to-end excel example, you will learn – How to Count rows that contain specific values in Excel.


How to Count rows that contain specific values in Excel

Generic formula



To count rows that contain specific values, you can use an array formula based on the MMULT, TRANSPOSE, COLUMN, and SUM functions. In the example shown, the formula in G5 is:


where data is the named range B4:B12.

Note: this is an array formula and must be entered with control shift enter.

How this formula works

Working from the inside out, the logical criteria used in this formula is:


where data is the named range B4:D12. This generates a TRUE / FALSE result for every value in data, and the double negative coerces the TRUE FALSE values to 1 and 0 to yield an array like this:


Like the original data, this array is 9 rows by 3 columns (9 x 3) and goes into the MMULT function as array1.

Array2 is derived with:


This is the tricky and fun part of this formula. The COLUMN function is used simply for convenience as a way to generate a numeric array of the right size. To perform matrix multiplication with MMULT, the column count in array1 (3) must equal the row count in array2.

COLUMN returns the 3-column array {2,3,4}, and TRANSPOSE changes this array to the the 3-row array {2;3;4}. MMULT then runs and returns a 9 x 1 array result:


We check for non-zero entries with >0 and again coerce TRUE FALSE to 1 and 0 with a double negative to get a final array inside SUM:


In this final array, a 1 represents a row where the logical test (data=90) returned true. The total returned by SUM is a count of all rows that contain the number 90.

Personal Career & Learning Guide for Data Analyst, Data Engineer and Data Scientist

Applied Machine Learning & Data Science Projects and Coding Recipes for Beginners

A list of FREE programming examples together with eTutorials & eBooks @ SETScholars

95% Discount on “Projects & Recipes, tutorials, ebooks”

Projects and Coding Recipes, eTutorials and eBooks: The best All-in-One resources for Data Analyst, Data Scientist, Machine Learning Engineer and Software Developer

Topics included: Classification, Clustering, Regression, Forecasting, Algorithms, Data Structures, Data Analytics & Data Science, Deep Learning, Machine Learning, Programming Languages and Software Tools & Packages.
(Discount is valid for limited time only)

Disclaimer: The information and code presented within this recipe/tutorial is only for educational and coaching purposes for beginners and developers. Anyone can practice and apply the recipe/tutorial presented here, but the reader is taking full responsibility for his/her actions. The author (content curator) of this recipe (code / program) has made every effort to ensure the accuracy of the information was correct at time of publication. The author (content curator) does not assume and hereby disclaims any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from accident, negligence, or any other cause. The information presented here could also be found in public knowledge domains.

Learn by Coding: v-Tutorials on Applied Machine Learning and Data Science for Beginners

Please do not waste your valuable time by watching videos, rather use end-to-end (Python and R) recipes from Professional Data Scientists to practice coding, and land the most demandable jobs in the fields of Predictive analytics & AI (Machine Learning and Data Science).

The objective is to guide the developers & analysts to “Learn how to Code” for Applied AI using end-to-end coding solutions, and unlock the world of opportunities!


How to transpose a matrix in R

C++ for Beginners: C++ Program to Find Transpose of a Matrix

Learn Java by Example: Java Program to Find Transpose of a Matrix