Sum in excel based on cell colour

Posted on 2014-07-10
Last Modified: 2014-07-11
hi Folks
Is there a way to sum a range based on its colour e.g. in the attached sheet. All the yellow cells added up together are 500. Is there some way to use the Sumif or some other way to automatically add up cells based on their colour. Thanks.
Question by:agwalsh
    LVL 47

    Accepted Solution


    pls try this UDF

    Function SumByColor(rng As Range)
    ColIdx = Application.Caller.Interior.ColorIndex
    For Each c In rng
      If c.Interior.ColorIndex = ColIdx Then
        mySum = mySum + c
      End If
    Next c
    SumByColor = mySum
    End Function


    Author Comment

    Brilliant...does the job. I just got thrown by the fact that I have to put the UDF in the actual coloured box :-) to get it to work properly...thank you :-)

    Author Closing Comment

    Does exactly what it says on the tin. If using this, make sure you put the function in the cell with the colour you want to sum by.
    LVL 8

    Expert Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
    No matter the version of Windows you are using, you may have some problems with Windows Search running too slow or possibly not running at all. Before jumping into how you can solve this issue, just know there are many other viable alternative deskt…
    The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    760 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

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now