by Allen Wyatt
(last updated December 8, 2018)
Mandy wonders if there is a way to sum a data range and include in the sum only those cells that contain a formula. According to Mandy's needs, if a cell contains an explicit value and not a formula, then it should not be included in the sum.
There are many ways you could go about achieving the desired result, but I will focus on only a few of them.
First, if you only need to determine the sum a single time and not have it appear within the worksheet itself, then you can follow these steps:
At this point you can look in the status bar (bottom of the Excel window) and see the sum of the selected cells—those containing formulas.
If you prefer a formula-based approach, one of the key factors here is going to be the version of Excel you are using. Microsoft introduced the ISFORMULA function with the release of Excel 2013, so if you are using that version (or later), determining the sum you want is quite easy. Just use this formula:
This formula assumes that the data range you want to sum is A1:A5. The "double minus" sign before the ISFORMULA function is used to convert TRUE and FALSE values (as returned by ISFORMULA) to either 1 or 0.
If you prefer to use an array formula, you could use the following formula:
Just remember to enter using Ctrl+Shift+Enter and you'll get the proper result.
If you are using a version of Excel older than Excel 2010, then these formulas won't work. Instead, you'll need to rely on a user-defined function to do the trick:
Function SumFormulas(ByVal r As Range) Dim c As Range Dim s As Double s = 0 For Each c In r.Cells If c.HasFormula And IsNumeric(c) Then s = s + c.Value End If Next c SumFormulas = s End Function
Note that the code checks to make sure that the cell contains a formula (using the HasFormula property) and checks to make sure it is numeric (using the IsNumeric function). Both are necessary because it is possible to have a text-based formula in a cell, and you don't want to try to include the results of such a formula in your sum.
In order to use the function, you would simply use the following in a worksheet cell, assuming you want to sum the range A1:C7:
The macro-based approach will also work in versions of Excel beyond Excel 2010, if for some reason you don't want to rely on the ISFORMULA function. (For instance, if you have to ensure compatibility with older versions of Excel.)
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13595) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Office 365.
Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!
Need to count the number of W (win) or L (loss) characters in a range of cells? You can develop a number of formulaic ...Discover More
Sometimes it is helpful to have a cell contain the maximum value that has ever occurred within changing data. This tip ...Discover More
Need to figure out the lowest score in a range of scores? Here's the formulas to get the information you need.Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.