How to sum only filtered or visible cells in Excel?
Maybe it is easy for you to sum a column of numbers in Excel, but sometimes you need to filter or hide some data to meet your criteria. After hiding or filtering, and now you just want to add up only the filtered or visible values. If you apply the Sum function in Excel, all the values including the hidden data will be added, in this case, how could you sum only the filtered or visible cell values in Excel?
Classic Menu for Office: Bring Back Old Look to Office 2010 and 2013 (includes Office 365).
Office Tab: Bring Tabbed Editing and Browsing Features to Office, Just Like Chrome, Firefox, Internet Explorer 8/9/10.
With this SUBTOTAL function which ignores rows that have been excluded by a filter, you can easily add up only the visible cells. You can do as this:
Supposing you have a range of data, and they have been filtered as you need, see screenshot:
1. In a blank cell, C13 for example, enter this formula: =Subtotal(109,C2:C12), see screenshot:
2. Then press Enter key and the subtotal value of only the filtered data has been worked out.
1. The number 109 in the above formula is indicated that when you sum the numbers, the hidden values will be ignored.
2. This formula also can help you sum only the visible cells if there are hidden rows in your worksheet.
If you are interested in the following code, it also can help you to sum only the visible cells.
1. Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications window.
2. Click Insert > Module, and paste the following code in the Module window.
Function SumVisible(WorkRng As Range) As Double 'Update 20130907 Dim rng As Range Dim total As Double For Each rng In WorkRng If rng.Rows.Hidden = False And rng.Columns.Hidden = False Then total = total + rng.Value End If Next SumVisible = total End Function
3. Save this code and enter the formula =SumVisible(C2:C12) into a blank cell. See screenshot:
4. Then press Enter key and you will get the result that you want.