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?


Sum only filtered or visible cell values with formula

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) (109 indicates when you sum the numbers, the hidden values will be ignored; C2:C12 is the range you will sum ignoring filtered rows.), and press the Enter key.

Note: This formula also can help you sum only the visible cells if there are hidden rows in your worksheet. However, this formula can't sum with ignoring cells in hidden columns.

Sum/Count/Average visible cells only in a specified range with ignoring hidden or filtered cells/rows/columns

The normally SUM/Count/Average function will count all cells in the specified range on matter cells are hidden/filtered or not. While the Subtotal function can only sum/count/average with ignoring hidden rows. However, Kutools for Excel SUMVISIBLE / COUNTVISIBLE / AVERAGEVISIBLE functions will easily calculate the specified range with ignoring any hidden cells, rows, or columns. Full Feature Free Trial 30-day!
ad sum count average visible cells only

Sum only filtered or visible cell values with User Defined Function

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.


Sum/Count/Average only filtered or visible cells with Kutools for Excel

If you have Kutools for Excel installed, you can quickly calculate the sum/count/average only visible or filtered out cells in Excel easily.

Kutools for Excel - Includes more than 300 handy tools for Excel. Full feature free trial 30-day, no credit card required! Get It Now

For example you want to sum only visible cells only, please select the cell you will place the summing result at, type the formula =SUMVISIBLE(C3:C12) (C3:C13 is the range where you will sum only visible cells) into it, and press the Enter key.

And then the summing result is calculated with ignoring all hidden cells. See screenshot:

For counting only visible cells, please apply this formula =COUNTVISIBLE(C3:C12); For averaging only visible cells, please apply this formula =AVERAGEVISIBLE(C3:C12).

Note: If you can't remember the formulas exactly, you can following below steps to sum/count/average only visible cells easily:

1. Select the cell you will place the summing result into, and click Kutools > Functions > Statistical & Math > SUMVISIBLE (or AVERAGEVISBLE, COUNTVISIBLE as you need). See screenshot:

2. In the opening Function Arguments dialog box, please specify the range where you will sum ignoring hidden cells, and click the OK button. See screenshot:

Kutools for Excel - Includes more than 300 handy tools for Excel. Full feature free trial 30-day, no credit card required! Get It Now

And then the summing result is calculated with ignoring all hidden cells.


Demo: Sum/Count/Average only filtered or visible cells


Kutools for Excel includes more than 300 handy tools for Excel, free to try without limitation in 30 days. Download and Free Trial Now!

Easily sum/count only filtered out/visible cells by deleting hidden rows in Excel

When summing/counting filtered out cells in Excel, the SUM function or Count function will not ignore hidden cells. If hidden/filtered rows are removed, we can only sum or count visible cells easily. You can try Kutools for Excel's Delete Hidden (Visible) Rows & Columns utility to solve it. Full Feature Free Trial 30-day!
ad delete hidden rows columns 3

Related articles:


The Best Office Productivity Tools

Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial. 60-day money back guarantee.
kte tab 201905

Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
officetab bottom
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    khilbadebade@gmail.com · 2 years ago
    how to skip hidden cells from excel formulae in filtered sheet....

    yellow coloured cells are involving hidden cells due to filter....
    • To post as a guest, your comment is unpublished.
      kelly.extendoffice@gmail.com · 2 years ago
      Hi,
      What kinds of calculation do you need to do? Kutools for Excel supports three functions to count/sum/average ignoring all hidden cells.
      • To post as a guest, your comment is unpublished.
        khilbadebade@gmail.com · 2 years ago
        or like this



        column a column d

        100 10

        90 10

        80 10



        where 90=100-10, 80=90-10, and so on.........

        dragging the formula includes hidden cells in formula
      • To post as a guest, your comment is unpublished.
        khilbadebade@gmail.com · 2 years ago
        When i am applying say G3-K2 Formula in filtered excel sheet & dragging the formula, it includes hidden cells

        for example



        Validity Lifting Qty
        27054.59 123.41
        26931.18 330.98
        26600.20 493.66
        26106.54 476.38
        25630.16 480.64
        25149.52 577.06


        now value in validity comes after get subtracted by lifted qty (like 2nd value 26931.18=27054.59-123.41)

        3rd value in validity=2nd value in validity-2nd value in lifted qty. and so on.....

        now this sheet is filtered & when i drag the formulae in validity column, it includes hidden cells, due to filter.

        which gives me wrong result
      • To post as a guest, your comment is unpublished.
        half yodha · 2 years ago
        Validity Lifting Qty
        27054.59 123.41
        26931.18 330.98
        26600.20 (26600.2=26931.18-330.98) 493.66
        26106.54 476.38
        25630.16 480.64
        25149.52 577.06
      • To post as a guest, your comment is unpublished.
        half yodha · 2 years ago
        When i am applying say G3-K2 Formula in filtered excel sheet & dragging the formula, it includes hidden cells

        for example



        Validity Lifting Qty
        27054.59 123.41
        26931.18 330.98
        26600.20 493.66
        26106.54 476.38
        25630.16 480.64
        25149.52 577.06


        now value in validity comes after get subtracted by lifted qty (like 2nd value 26931.18=27054.59-123.41)

        3rd value in validity=2nd value in validity-2nd value in lifted qty. and so on.....

        now this sheet is filtered & when i drag the formulae in validity column, it includes hidden cells, due to filter.

        which gives me wrong result
        • To post as a guest, your comment is unpublished.
          kelly.extendoffice@gmail.com · 2 years ago
          Hi,
          The normal =G3-K2 will not ignore any hidden cells/rows/column by dragging to copy. I am sorry I can not figure out a proper formula for your. All formulas or methods talked in this article is just about sum/count/average ignoring hidden cells.
  • To post as a guest, your comment is unpublished.
    half yodha · 2 years ago
    how i can skip hidden cells from excel formulae in filtered sheet
  • To post as a guest, your comment is unpublished.
    Sab6247 · 4 years ago
    Im trying to use the AVERAGEVISIBLE function to average the 12 largest values in a column, this works in the normal AVERAGE function as

    =AVERAGE(LARGE(E971:E1540,{1,2,3,4,5,6,7,8,9,10,11,12})) however when i try to use the average visible function it returns #VALUE!, any ideas?
  • To post as a guest, your comment is unpublished.
    JPas · 4 years ago
    This is awesome! Thanks so much.
  • To post as a guest, your comment is unpublished.
    DataCruncher · 4 years ago
    Sorry I messed up the posts security code at bottom and seems like my question may have been deleted as it asked me to try another one.

    I can get the VBA code for SUMVISIBLE to work well if my data is vertical and I hide rows. However it doesn't if my data runs horizontal and I want to hide columns. Is there a way to program this? Thanks!
  • To post as a guest, your comment is unpublished.
    DataCrucher · 4 years ago
    I am able to get your VBA for =SUMVISIBLE above to work good.
    However just if my data runs vertically and I am hiding rows.
    Is there a way to program it so you can have your data run horizontally and it still work when you hide columns? THANKS!
  • To post as a guest, your comment is unpublished.
    ExcelNewbie · 5 years ago
    The solution worked for me. :D
  • To post as a guest, your comment is unpublished.
    MJK · 5 years ago
    Thanks a lot!! It was very helpful:)
  • To post as a guest, your comment is unpublished.
    Steve Ostroff · 5 years ago
    I had a similar issue where I wanted to calculate differences from two cells in different rows where I use a Data Filter to discriminate which rows are displayed. I solved the problem in the following method:

    1. Create a new column [or Row depending on what is hidden] and label it Visible.
    2. Create a new column that will be used to maintain the value from the last "visible" row that you want to bring down.
    3. In the "Visible" column, use the formula: =+SUBTOTAL(102,cell_in_row_or_column)
    This will have a 1 as soon as you type it, but will be 0 if the cell is not visible.
    4. In the column created for step 2, you need a simple formula: +IF(A,B,C); where A=cell returning Visible status, B the value you want to operate on from the same row [just a copy], C the value from the same cell in the row previous since the cell is not visible.

    In this way, the last "Visible" item is propagated behind the scenes to the row above the visible row(s). This allows you to create simple formulas performing the operations on the preceding row. This works for many situations where you need to deal with individual data points, as opposed to ranges which are better with Subtotal.
  • To post as a guest, your comment is unpublished.
    Pretti · 5 years ago
    hi when i sue this function, and filter, the totals dont display. why?
  • To post as a guest, your comment is unpublished.
    Roy Rouessart · 6 years ago
    When you unhide rows then "=SumVisible()" reflects error.
    Is it possible to change "Function" to reflect either "Zero" or "No hidden Rows"?
    • To post as a guest, your comment is unpublished.
      Roy Rouessart · 6 years ago
      Thanks Milinda - I have inserted the module in both "Book 1" and "Personal.xlsb" but when I open a new file I don't seem able to access the function. Please what have I done wrong?
  • To post as a guest, your comment is unpublished.
    alex17111 · 6 years ago
    How do i add criteria to the 2nd option.
    Eg.if i have a range of values i want it to select values which have criteria of "X" in a column.
  • To post as a guest, your comment is unpublished.
    Paul_007 · 6 years ago
    Hi All,

    I would like to add two values in different collumns, but only with visible cells when I use a filter.
    eg. B3=B2+A3
    I have tried to use the SUBTOTAL function, but that does not work.
    Please advise, thanks in advance!
    regards,
    • To post as a guest, your comment is unpublished.
      Milind Ranka · 6 years ago
      Create a row on top of the row you will choose to apply filter.
      In the column for which you need total write the formula
      =subtotal(9,{start column no.},{end column no})

      For example
      if for column A i need the subtotals based on value in column b
      then if the header row for data is in row 2 and row 1 is blank
      then put the formula in column A1 as =subtotal(9,A2:a999)

      As you change the filter condition on column B you will see total changing.