How to Use COUNTA from SUBTOTAL Function in Excel

In this tutorial, I am going to show you 5 suitable examples of how to use the SUBTOTAL COUNTA function in excel. You can use these examples in your own dataset to find out various subtotal values. Throughout this tutorial, you will also learn some important excel tools and techniques which will be very useful in any excel related task.


Download Practice Workbook

You can download the practice workbook from here.


COUNTA Function as SUBTOTAL Parameter

The SUBTOTAL function in excel can take multiple functions as its first parameter. We can specify the COUNTA function by passing 3 as the first parameter. After that, we need to pass the range of values that we want to get the subtotal from. The SUBTOTAL function can either include or exclude certain values which make sit very useful for calculation in a table.


5 Suitable Examples to Use SUBTOTAL COUNTA Function in  Excel

We have taken a concise dataset to explain the steps clearly. The dataset has approximately 7 rows and 2 columns. Initially, we are keeping all the cells in General format. For all the datasets, we have 2 unique columns which are Items and Sales (units). Although we may vary the number of columns later on if that is needed.

subtotal counta in excel


1. Counting Item Types

The most simple example of using the COUNTA function inside the SUBTOTAL function in excel is to count all the cells that have any type of data. Let us see this in practice.

Steps:

  • First, go to cell C10 and insert the following formula:
=SUBTOTAL(3,C5:C9)

how to use the SUBTOTAL COUNTA function in excel for counting item types

  • Now, press Enter and this will calculate the total different item types inside cell C10.


2. Using SUBTOTAL in Filtered Items

When we use the COUNTA function inside the SUBTOTAL function in excel, it will exclude all the data we filter out using the excel Filter feature. Follow the steps below to build this example.

Steps:

  • To begin with, double-click on cell C10 and enter the below formula:
=SUBTOTAL(3,C5:C10)

how to use the SUBTOTAL COUNTA function in excel to count filtered data

  • Next, press the Enter key which should give you the item types count.
  • Then, go to the Data tab and click on Filter.

  • Now, click on the drop-down on the Items heading and uncheck Raspberries for example.
  • Then click OK.

  • As a result, the formula will no longer count the row we just filtered and the total count will now be 5.


3. Finding Nested SUBTOTAL

If we include any nested SUBTOTAL formula along with the data rows in excel, the COUNTA function will not take them into count. Let us see this example below in detail.

Steps:

  • To begin this method, double-click on cell D8 and insert the formula below:
=SUBTOTAL(3,D5:D7)

how to use the SUBTOTAL COUNTA function in excel to find nested subtotal

  • Next, press the Enter key and type in the following formula inside cell D12:
=SUBTOTAL(3,D9:D11)

  • After that, press the Enter key again and enter this formula in the cell D13:
=SUBTOTAL(3,D5:D12)

  • Finally, press Enter and you should see that the last formula did not count the previous SUBTOTAL values and counted only the items.


4. Counting Data with Hidden Row

In case we hide any row manually when using the COUNTA function inside the SUBTOTAL function, the data will come into count even though we can not see that row. Follow the steps below to do this.

Steps:

  • As previously, insert the below formula inside cell C10:
=SUBTOTAL(3,C5:C10)

how to use the SUBTOTAL COUNTA function in excel to count data with hidden rows

  • Then, press Enter and right-click on any of the row numbers.
  • Now, click on Hide.

  • Consequently, this will hide the row but the formula will still count that hidden row making the resulting value still 6.


5. Applying SUBTOTAL in VBA

If you are familiar with VBA in excel, you can apply the COUNTA function inside the SUBTOTAL function with just a few lines of code. Let us see how we can do this.

Steps:

  • For this method, go to the Developer tab and select Visual Basic.

how to use the SUBTOTAL COUNTA function in excel vba

  • Now, select Insert in the VBA window and click on Module.

  • Next, type in the formula below in the new window:
Public Sub Subtotal_Counta()
Range("C11").Formula = "=SUBTOTAL(3,C5:C10)"
End Sub

  • Then, open the macro from the Developer tab by clicking on Macros.

  • Now, in the Macro window, select the Subtotal_Counta macro and click Run.

  • As a result, the VBA code will calculate the total item types as 6.


Conclusion

I hope that you were able to apply the methods that I showed in this tutorial on how to use the SUBTOTAL COUNTA function in excel. As you can see, there are quite a few ways to achieve this. So wisely choose the method that suits your situation best. If you get stuck in any of the steps, I recommend going through them a few times to clear up any confusion. Lastly, to learn more excel techniques, follow our ExcelDemy website. If you have any queries, please let me know in the comments.

Nazmul Hossain Shovon

Nazmul Hossain Shovon

Hello, I am Nazmul Hossain. I am currently working full-time in Exceldemy as an Excel & VBA Content Developer. I have completed my bachelors in Naval Architecture and Marine Engineering from Bangladesh University of Engineering and Technology. I am interested in working with MS Excel. I also like coding web applications a lot.

We will be happy to hear your thoughts

Leave a reply

ExcelDemy
Logo