Sum cells that have no formula

Posted on 2014-09-10
Last Modified: 2014-09-11
I have data in a ranges (rows) where the cells in the range contain a formula for forecasting.  Users are to overwrite the formula when actual figures are known and I have conditional formatting to highlight the cell.  I would like a formula to sum the actual numbers entered for each row and not include the cells with formulas.  I tried defining a VBA function to test for cell color but it will not pick up conditional formatting changes.

Any help on this please?
Question by:acdecal
  • 3
  • 3
LVL 19

Expert Comment

by:Ken Butters
ID: 40315626
Since the cell is going to be updated to no longer contain a formula...

I would suggest that you just test for the existence of a forumla...

Dim myCell as range

if myCell.HasFormula then....


if not myCell.HasFormula then....

Author Comment

ID: 40315632
Is there a non VBA function I can use in a SUMIF ?
LVL 19

Expert Comment

by:Ken Butters
ID: 40315697
I don't believe there is a built in one...

but thinking you could use define it like this in vba:

Function containsFormula(aCellRange As Range) 
    containsFormula = aCellRange.HasFormula 
End Function

Open in new window

Then use =containsFormula in your worksheet or in your sumif function.
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center


Author Comment

ID: 40315743
I tried =SUMIF(AB10:AQ10,ContainsFormula(AB10:AQ10))  but not working.  Any thoughts?
LVL 19

Accepted Solution

Ken Butters earned 500 total points
ID: 40315822
You are right sumif... doesn't like that for the criteria....

I tried this... this seemed to do what you are asking:

After adding this vba code... then in your sheet you can use it like this:


it will include in the sum... any of the cells that do NOT contain a formula.

Function sumIfNoFormula(aCellRange As Range)
    Dim aCell As Range
    sumIfNoFormula = 0
    For Each aCell In aCellRange
        If Not aCell.HasFormula Then
            sumIfNoFormula = sumIfNoFormula + aCell.Value
        End If
End Function

Open in new window


Expert Comment

ID: 40315900
change your formula to make the resulting figure text instead of a number.
sum won't add text fields.

Author Closing Comment

ID: 40316727
That did the trick!  Thanks

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question