Skip to content
Free Excel Tutorials
  • Home
  • Excel For Beginners
  • Excel Intermediate
  • Advanced Excel For Experts

Data Analysis

  • Conditional Formatting Icon Sets Examples in Excel
  • Randomize/ Shuffle List in Excel
  • Example of COUNTIFS with variable table column in Excel
  • How to calculate current stock or inventory in Excel
  • Working With Tables in Excel

References

  • How to get address of named range in Excel
  • Extract data with helper column in Excel
  • Left Lookup in Excel
  • How to get relative row numbers in a range in Excel
  • Lookup entire row in Excel

Data Validations

  • Excel Data validation allow weekday only
  • Excel Data validation exists in list
  • Excel Data validation don’t exceed total
  • Excel Data validation must begin with
  • Excel Data validation number multiple 100

Count visible rows only with criteria in Excel

by

This tutorial shows how to Count visible rows only with criteria in Excel using the example below;

Formula

=SUMPRODUCT((range=criteria)*(SUBTOTAL(3,OFFSET(range,rows,0,1))))

Explanation

To count visible rows only with criteria, you can use a rather complex formula based on SUMPRODUCT, SUBTOTAL, and OFFSET.

The problem

The SUBTOTAL function can easily generate sums and counts for hidden and non-hidden rows. However, it isn’t able to handle criteria (i.e. like COUNTIF or SUMIF).

The solution

The solution is to use SUMPRODUCT to apply both the SUBTOTAL function (via OFFSET) and the criteria. In the example shown, the formula in C12 is:

=SUMPRODUCT((C5:C8=C10)*(SUBTOTAL(103,OFFSET(C5,ROW(C5:C8)-MIN(ROW(C5:C8)),0))))

How this formula works

The core of this formula is the array calculations inside of SUMPRODUCT. The first array applies the criteria, and the second array handles the “visibility problem”.

=SUMPRODUCT(criteria*visibility)

The criteria is applied with part of the formula:

=(C5:C8=C10)

Which generates an array like this:

Worked Example:   Count sold and remaining in Excel

{FALSE;TRUE;FALSE;TRUE}

Where TRUE means “meets criteria”. Note that because we are using multiplication (*) inside the first (and only) array given to SUMPRODUCT, the TRUE FALSE values will automatically be converted to:

Worked Example:   Count cells not equal to many things in Excel

{0;1;0;1}

The visibility filter is applied using SUBTOTAL.

SUBTOTAL is able to exclude hidden rows in a variety of calculations, so we can use it in this case to generate a “filter” to exclude hidden rows inside of SUMPRODUCT. The problem though is that SUBTOTAL returns a single number, while we need an array to use it successfully inside SUMPRODUCT.

The trick is to use OFFSET to feed SUBTOTAL one reference per row, so that OFFSET will return one result per row.

Worked Example:   How to test a range for numbers in Excel

Of course, that requires another trick, which is to give OFFSET an array that contains one number per row, starting with zero. We do that using:

=ROW(C5:C8)-MIN(ROW(C5:C8)

Which will generate an array like this:

{0;1;2;3}

So, the second array, which handles visibility using SUBTOTAL, is generated like this:

=SUBTOTAL(103,OFFSET(C5,ROW(C5:C8)-MIN(ROW(C5:C8)),0))
=SUBTOTAL(103,OFFSET(C5,{0;1;2;3},0))
=SUBTOTAL(103,{"East";"West";"Midwest";"West"})
={1;0;1;1}

And, finally, we have:

=SUMPRODUCT({0,1,0,1}*{1;0;1;1})

Which returns 1.

Multiple criteria

You can extend the formula to handle multiple criteria like this:

=SUMPRODUCT((range1=criteria1)*(range2=criteria2)*(SUBTOTAL(3,OFFSET(range,rows,0,1))))

Post navigation

Previous Post:

44 Practical Excel IF function Examples

Next Post:

Large with criteria in Excel

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Learn Basic Excel

Ribbon
Workbook
Worksheets
Format Cells
Find & Select
Sort & Filter
Templates
Print
Share
Protect
Keyboard Shortcuts

Categories

  • Charts
  • Data Analysis
  • Data Validation
  • Excel Functions
    • Cube Functions
    • Database Functions
    • Date and Time Functions
    • Engineering Functions
    • Financial Functions
    • Information Functions
    • Logical Functions
    • Lookup and Reference Functions
    • Math and Trig Functions
    • Statistical Functions
    • Text Functions
    • Web Functions
  • Excel VBA
  • Excel Video Tutorials
  • Formatting
  • Grouping
  • Others

Logical Functions

  • SWITCH function: Description, Usage, Syntax, Examples and Explanation
  • AND function: Description, Usage, Syntax, Examples and Explanation
  • Invoice status with nested if in Excel
  • IF, AND, OR and NOT Functions Examples in Excel
  • TRUE function: Description, Usage, Syntax, Examples and Explanation

Date Time

  • WORKDAY function: Description, Usage, Syntax, Examples and Explanation
  • Get days, months, and years between dates in Excel
  • Calculate days remaining in Excel
  • Display Days until expiration date in Excel
  • Get project midpoint in Excel

Grouping

  • If cell contains one of many things in Excel
  • Group numbers with VLOOKUP in Excel
  • Group arbitrary text values in Excel
  • Running count group by n size in Excel
  • Group numbers at uneven intervals in Excel

General

  • How to fill cell ranges with random number from fixed set of options in Excel
  • AutoRecover file that was never saved in Excel
  • How to calculate percent sold in Excel
  • How to calculate percent of goal in Excel
  • Subtotal by invoice number in Excel
© 2023 xlsoffice . All Right Reserved. | Teal Smiles | Abbreviations And Their Meaning