Summary

To search an entire worksheet for a value and return a count, you can use a formula based on the COUNTIF function.

In the example shown, the formula in C5 is:

=COUNTIF(Sheet2!1:1048576,C4)

Generic formula

=COUNTIF(Sheet2!1:1048576,"apple")

Explanation 

The second sheet in the workbook, Sheet2, contains 1000 first names in the range B4:F203.

1000 first names on Sheet2

The COUNTIF function takes a range and a criteria. In this case, we give COUNTIF a range equal to all rows in Sheet2.

Sheet2!1:1048576

Note: an easy way to enter this range is to use the Select All button.

For criteria, we use a reference to C4, which contains "John". COUNTIF then returns 15, since there are 15 cells in Sheet2 equal to "John".

Contains vs. Equals

If you want to count all cells that contain the value in C4, instead of all cells equal to C4, add the wildcards to the criteria like this:

=COUNTIF(Sheet2!1:1048576,"*"&C4&"*")

Now COUNTIF will count cells with the substring "John" anywhere in the cell.

Performance

In general, it's not a good practice to specify a range that includes all worksheet cells. Doing so can cause major performance problems, since the range includes millions and millions of cells. When possible, restrict the range to a sensible area.

Dave Bruns Profile Picture

AuthorMicrosoft Most Valuable Professional Award

Dave Bruns

Hi - I'm Dave Bruns, and I run Exceljet with my wife, Lisa. Our goal is to help you work faster in Excel. We create short videos, and clear examples of formulas, functions, pivot tables, conditional formatting, and charts.