To search multiple worksheets in a workbook for a value and return a count, you can use a formula based on the COUNTIF and INDIRECT functions. With some setup, you use this approach to search an entire workbook for a specific value.
The workbook contains 4 worksheets total. Sheet1, Sheet2, and Sheet3 each contain 1000 random first names that look like this:
How this formula works
The range B7:B9 contains the Sheets we want to count.
Working from the inside out, this expression is used to build a full sheet reference:
The single quotes are added to allow sheet names with spaces, and the exclamation mark is a standard syntax for ranges that include a sheet name. The text "1:1048576" is a range that includes every row in the worksheet.
After B7 is evaluated, and values are concatenated, the expression above returns:
which is goes into the INDIRECT function as the 'ref_text' argument. INDIRECT then evaluates this text and returns a standard reference to every cell in Sheet1. This goes into the COUNTIF function as the range. The criteria is provided as an absolute reference to C4 (locked so the formula can be copied down column C).
COUNTIF then returns a count of all cells with a value equal to "mary", 25 in this case.
Note: COUNTIF is not case-sensitive.
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:
Now COUNTIF will count cells with the substring "John" anywhere in the cell.
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. In this example, the problem is compounded, since the formula uses the INDIRECT function, which is a volatile function. Volatile functions recalculate on every worksheet change, so the impact on performance can be huge.
When possible, restrict all ranges to a sensible size.
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 ) How this formula works The second sheet in the...
To count matches in entire workbook, you can use a formula based on the COUNTIF and SUMPRODUCT functions. In the example shown, the formula in D5 is: = SUMPRODUCT ( COUNTIF ( INDIRECT ( "'" & sheets & "'!A1:Z10000" ), B5...
COUNTIF is a function to count cells that meet a single criteria. COUNTIF can be used to count cells with dates, numbers, and text that match specific criteria. The COUNTIF function supports logical operators (>,...
The Excel INDIRECT function returns a valid reference from a given text string. Use INDIRECT when you need to convert a reference assembled as text into a proper reference.
Excel Formula Training
Learn Excel formulas and functions with concise, clear videos. Master absolute/relative addresses, dates, text, named ranges, and tools for troubleshooting. Each video comes with a practice worksheet and audio transcript. Instant access and complete 100% guarantee. Start today!