+ Reply to Thread
Results 1 to 9 of 9

Sum By Colour

Hybrid View

  1. #1
    Registered User
    Join Date
    03-09-2013
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    11

    Sum By Colour

    I want to be able to sum the different colours in my spreadsheet.
    The colours are decided by conditional formatting on the cell, so these colours will change when different data is entered.
    Is there a formula that will count the coloured cells only?

    I have had a look but can only find answers suggesting VBA is the way to go. This is a touch over my head at the minute though.

  2. #2
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: Sum By Colour

    Hi sigmundo,

    A quick way would be to filter by color and use Subtotal function to sum, see attached:-

    sum by color.xlsx

    Regards,
    DILIPandey
    <click on below * if this helps>
    DILIPandey, Excel rMVP
    +919810929744 (India), +971528225509 (Dubai), dilipandey@gmail.com

  3. #3
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: Sum By Colour

    There is NO formula that will count colours, if you use what you use for the conditional formatting as parameters for a COUNTIF/S function, you may be able to work with that, BUT COLOURS are not data, they are formatting (ie- what you see, not what is), if you need to do colour counting/calculations, you probably need to use VBA....
    A picture may be worth a thousand words, BUT, a sample Workbook is worth a thousand screenshots!
    -Add a File - click advanced (next to quick post), scroll to manage attachments, click, select add files, click select files, select file, click upload, when file shows up at bottom left, click done (bottom right), click submit
    -To mark thread Solved- go top of thread,click Thread Tools,click Mark as Solved
    If you received helpful response, please remember to hit the * of that post

  4. #4
    Registered User
    Join Date
    03-09-2013
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Sum By Colour

    What I need to do is count the numbers in the coloured cells as in the example from Dilipandey.
    How do i tell Excell which colours to look for?
    I have a total of 4 different colours
    Also, not all cells in the relevant column are coloured the same.
    So I may just want to count the red cells.
    Last edited by sigmundo76; 03-24-2013 at 05:46 AM.

  5. #5
    Registered User
    Join Date
    07-13-2010
    Location
    Module1
    MS-Off Ver
    Excel 2010
    Posts
    29

    Re: Sum By Colour

    Here is a VBA alternative:

    Use the function "SUMOFCOLOR"
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    03-09-2013
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Sum By Colour

    That's exactly it Fred.

    How do I implement it into my workbook though?

    I got a #NAME error.

    Does it make a difference if the cells are coloyred when they meet certain conditions set in conditional formatting?

  7. #7
    Registered User
    Join Date
    07-13-2010
    Location
    Module1
    MS-Off Ver
    Excel 2010
    Posts
    29

    Re: Sum By Colour

    Quote Originally Posted by sigmundo76 View Post
    That's exactly it Fred.

    How do I implement it into my workbook though?
    Function SUMOFCOLOR(rCol As Range, iCol As Range)
    
        Dim Cell As Range
        
        A = iCol.Interior.ColorIndex
        cnt = 0
    
        For Each Cell In rCol
            If Cell.Interior.ColorIndex = A Then
                cnt = cnt + Cell.Value
            End If
        Next Cell
        
        SUMOFCOLOR = cnt
        
    End Function

    1)Copy the sample code above
    2)Open the workbook in which you want to add the code
    3)Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
    4)Choose Insert | Module
    5)Where the cursor is flashing, choose Edit | Paste



    Quote Originally Posted by sigmundo76 View Post
    Does it make a difference if the cells are coloyred when they meet certain conditions set in conditional formatting?
    I'm not sure I understand what you mean.

    The function SUMOFCOLORS will look at the current color on the selected cells.

    Hope that helps.

  8. #8
    Forum Expert Kevin UK's Avatar
    Join Date
    12-07-2010
    Location
    Radstock, Somerset
    MS-Off Ver
    365
    Posts
    1,922

    Re: Sum By Colour

    Hi sigmundo76

    Use your conditional formatting. For example if you have conditional formatted column A to highlight numbers less <50. Use =SUMIF(A:A,"<50") to sum the cells which are coloured.
    Regards Kevin


    Merged Cells (They are the work of the devil!!!)

  9. #9
    Registered User
    Join Date
    07-13-2010
    Location
    Module1
    MS-Off Ver
    Excel 2010
    Posts
    29

    Re: Sum By Colour

    Quote Originally Posted by Kevin UK View Post
    Hi sigmundo76

    Use your conditional formatting. For example if you have conditional formatted column A to highlight numbers less <50. Use =SUMIF(A:A,"<50") to sum the cells which are coloured.
    This is probably the best alternative, Sigmund.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1