How to Count Filtered Rows with Criteria in Excel (5 Easy Ways)

For illustration, here is a dataset with the July Sales Report of fruit sales in the USA and Australia.

Excel Count Filtered Rows with Criteria

Filter this dataset.

  • Select cell range B4:D14.
  • Go to the Home tab and select Filter from the Sort & Filter drop-down in the Editing group.

  • The Filter tool in the Sort & Filter group can also be found under the Data tab.

  • The filter will be enabled in the dataset.

  • To filter this, click on the arrow beside the Product column.
  • We deselected Kiwi as we wanted to filter the other values.
  • Click OK.

  • You will get your filtered rows without the row for Kiwi.


Method 1 – Insert SUMPRODUCT Function to Count Filtered Rows with Criteria in Excel

  • Insert your preferred criteria for which you want to count rows.
  • We gave the product Orange as the Criteria in cell C16.

Insert SUMPRODUCT Function to Count Filtered Rows with Criteria in Excel

  • Insert this formula in cell C17.

=SUMPRODUCT((B5:B14=C16)*(SUBTOTAL(103,OFFSET(B5,ROW(B5:B14)-MIN(ROW(B5:B14)),0))))

Insert SUMPRODUCT Function to Count Filtered Rows with Criteria in Excel

  • Press Enter.
  • It will display the number of rows containing the special criteria.

  • The SUMPRODUCT function returns the sum product of the selected cell range B5:B14, based on the criteria in cell C17.
  • The SUBTOTAL function is used to get a return of the cumulative total with the function_num as 103. It defines that it will only count the visible cells in the dataset.
  • Insert the ROW function to return the row number from cell range B5:B14.
  • The MIN function is used to get the lowest value from those selected cells.
  • The OFFSET function returns the specified criteria in cell C16 from these rows and columns with 0 for an exact match.

Note: You can also insert this formula to count filtered rows with criteria. =SUMPRODUCT(SUBTOTAL(3,OFFSET(B5:B14,ROW(B5:B14)-MIN(ROW(B5:B14)),,1)),ISNUMBER(SEARCH("Orange",B5:B14))+0)


Method 2 – Count Filtered Rows with Criteria Using SUBTOTAL Function

  • Insert this formula in cell C16.

=SUBTOTAL(3,B5:B14)

Count Filtered Rows with Criteria Using SUBTOTAL Function

  • Press Enter.
  • We have created the general formula which will be applicable to any number of rows.
  • It shows the total number of rows before filtering.

We used the SUBTOTAL function to return the total number of selected criteria. The function_num argument is defined as 3 to specify the COUNTA function for visible cells in the cell range B5:B14.

  • Specify the criteria from the Filter context menu. We deselected Kiwi, Strawberry, and Watermelon.

  • Press OK.
  • The filtered rows with criteria will be counted and the result will be displayed in cell C16.

Excel Count Filtered Rows with Criteria

Read More: How to Count Visible Rows in Excel


Method 3 – Apply AGGREGATE Function for Counting Filtered Rows with Criteria in Excel

  • Filter the product names Apple and Banana defining them as criteria.

Apply AGGREGATE Function for Counting Filtered Rows with Criteria in Excel

  • Insert this formula in cell C16.

=AGGREGATE(3,3,B5:B14)

Apply AGGREGATE Function for Counting Filtered Rows with Criteria in Excel

  • Press Enter.
  • It will show the number of rows for the selected criteria.

The AGGREGATE function creates the opportunity to avoid hidden rows or error values from the cell range B5:B14.

  • To verify the formula, add Orange to the criteria from the Filter list.

  • Click OK.
  • The number for counted rows will change.


Method 4 – Count Filtered Rows with Criteria Inserting Help Column

  • Create a Help Column beside the original filtered dataset.
  • Insert this formula in cell D5.

=IF(B5="Orange",1,"")

Count Filtered Rows with Criteria Inserting Help Column

  • Press Enter.
  • Use the Fill Handle tool to drag this formula up to cell E14.

W used the IF function to compare our selected criteria Orange with the value in cell B5.

  • Insert this formula in cell C16.

=COUNTIFS(B5:B14,"Orange",E5:E14,"1")

Count Filtered Rows with Criteria Inserting Help Column

  • Press Enter and it will output the counted value of filtered rows with criteria.

We applied the COUNTIF function to count cell range B5:B14 which meets the condition in cell range E5:E14.


Method 5 – Excel VBA to Count Filtered Rows with Criteria

  • Filter your dataset according to your preferred criteria.

Excel VBA to Count Filtered Rows with Criteria

  • Go to the Data tab and select Visual Basic under the Code group.

  • Choose Module from the Insert section.

  • Insert this code on the blank page.
Function COUNTVISIBLE(Rw)
    Dim xCnt As Long
    Dim xRng As Range
    Application.Volatile
    For Each xRng In Rw
        If (Not xRng.EntireRow.Hidden) And (Not xRng.EntireColumn.Hidden) Then
            xCnt = xCnt + 1
        End If
    Next
    COUNTVISIBLE = xCnt
End Function

Excel VBA to Count Filtered Rows with Criteria

  • Save the code and close the window.
  • Insert this formula in cell C16.

=COUNTVISIBLE(B5:B13)

  • Press Enter and it will show the number of visible rows.

We applied the COUNTVISIBLE function to calculate the visible cells in the dataset. It will ignore the hidden cells during counting.


Download Practice Workbook


<< Go Back to Count Rows | Formula List | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Sanjida Mehrun Guria
Sanjida Mehrun Guria

Hello! Welcome to my blog. I have completed my Bachelor in Architecture from Ashanullah University of Science & Technology, Dhaka. I am a passionate, goal-oriented person with an immense thirst for knowledge and an attitude to grow continuously. Besides Architectural work, I find it very enthusiastic to work in Excel blogging. Exceldemy is a platform where I have got the opportunity to flourish my skill in Microsoft Excel and therefore, here I will be posting blogs related to... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo