Quick, clean, and to the point

Count occurrences in entire workbook

Excel formula: Count occurrences in entire workbook
Generic formula 

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:


where "sheets" is the named range B8:B10.


This workbook has four worksheets. Three of the worksheets, "Sheet1", "Sheet2", and "Sheet3" contain 1000 random first names in a table that looks like this:

Sample data - 1000 random names in each sheet

Note: the range we are using in the formula, A1:Z10000, is arbitrary and should be adjusted to suit your data.

How this formula works

Working from the inside out, we first have this expression inside the INDIRECT function:


Because "sheets" is a named range that contains "Sheet1", "Sheet2", and "Sheet3", we get an array like this once the expression is evaluated:


Inside the array, we have three values, and each is a sheet name joined via concatenation to the range A1:Z10000. Notice that these are all text values.

Next, the INDIRECT function is used to convert each text value to a proper reference, which are supplied to the COUNTIF function as the range argument, along with the value in D5 for criteria.

Since we've given COUNTIF three separate ranges, we get back three results in array like this:


Each item is a a count for one sheet.

Finally, SUMPRODUCT is used to sum the array, and returns a result of 16.

Dave Bruns

Excel Formula Training

Formulas are the key to getting things done in Excel. In this accelerated training, you'll learn how to use formulas to manipulate text, work with dates and times, lookup values with VLOOKUP and INDEX & MATCH, count and sum with criteria, dynamically rank values, and create dynamic ranges. You'll also learn how to troubleshoot, trace errors, and fix problems. Instant access. See details here.