Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, and 2016. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Summing Only Visible Values.

Summing Only Visible Values

by Allen Wyatt
(last updated February 25, 2017)

5

Kirk is using the SUM function in many of his worksheets to (naturally) determine the sum of a range of values. The problem he is running into, however, is that the range he is summing contains some hidden rows, and he doesn't want those values—the hidden ones—included in the sum.

The SUM function is pretty simplistic in how it does its work; it simply sums a range. You can change the function you use and get the desired results, however. For instance, let's assume that you want to sum the range of A3:A45, and that you don't want any hidden values to be included in the sum. You should use the SUBTOTAL function in the following manner:

=SUBTOTAL(109,A3:A45)

The first parameter of the function (109) indicates how you want SUBTOTAL to do its work. In this case, it means you want SUBTOTAL to sum the range, using the SUM function, and you don't want any hidden values included in the value returned. (You can find out more about the controlling SUBTOTAL parameters if you look in the online Help for the SUBTOTAL function.)

If you don't want to use the SUBTOTAL function for some reason, you can create your own user-defined function (a macro) that will only sum the visible values in a range. Consider this macro:

Function Sum_Visible(Cells_To_Sum As Object)
    Dim vTotal As Variant

    Application.Volatile
    vTotal = 0
    For Each cell In Cells_To_Sum
        If Not cell.Rows.Hidden Then
            If Not cell.Columns.Hidden Then
                vTotal = vTotal + cell.Value
            End If
        End If
    Next
    Sum_Visible = vTotal
End Function

To use the function, simply use a formula like this wherever you want your sum to appear:

=Sum_Visible(A1:A1000)

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12123) applies to Microsoft Excel 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Excel here: Summing Only Visible Values.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Misbehaving Rulers

When upgrading from Word 2000 to 2002, many people have a problem with the Ruler function. This tip explains how to fix the ...

Discover More

Indenting Cell Contents

Excel allows you to apply several types of alignments to cells. One type of alignment allows you to indent cell contents from ...

Discover More

Separating Grammar-Checking from Spell-Checking

Most of the time Word will check both grammar and spelling at the same time. You can, however, instruct the program to ...

Discover More

Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!

MORE EXCELTIPS (RIBBON)

Finding Positions of Formatted Characters in a Cell

With a little bit of work, Excel allows you to format individual characters of the text you place in a cell. If you want to ...

Discover More

Renaming a Macro

Got a macro that doesn't have quite the right name? You can rename the macro by following these simple steps.

Discover More

Automating Copying Macros

You can manually copy macros from one workbook to another, but what if you want to automate the copying process? Here's some ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments for this tip:

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 7 + 8?

2015-08-27 15:13:06

Ken Sadeckas

Another alternative is to:

1. Highlight the range to sum
2. Press F5 (to open the Go To menu)
3. Select Special
4. Choose "Visible cells only"
5. Enter your formula using the Sum function and highlighting the range again

The result is =SUBTOTAL(9,XXX:YYY) which only includes visible cells.


2015-08-27 07:19:49

Nancy Harpe

Sometimes the easiest formulas save the most time! I agree with JoyM, I wish I knew this years ago. It's a keeper! Thanks Allen!


2015-03-10 02:21:21

Bishnu

Dear sir,

=Sum_Visible(A1:A1000)

The above formula is not working with Excel 2007.

I hope your great replay.

Thank you.


2012-09-18 09:40:33

JanL

I generally format my data in a table and use the Total Row function. Anytime you filter data, the subtotal is automatically changed. It really is a lifesaver!


2012-09-17 08:20:44

JoyM

I cannot count the number of times this would have come in handy over ther past 10 years!!


Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.

Links and Sharing
Share