+ Reply to Thread
Results 1 to 2 of 2

Sum coloured cells!!!

Hybrid View

  1. #1
    Registered User
    Join Date
    03-19-2009
    Location
    Leeds, UK
    MS-Off Ver
    Excel 2003
    Posts
    2

    Sum coloured cells!!!

    You've probably seen this one a thousand times before but I can't get it to work for me!!
    I need to sum all the cells in a certain column that are coloured orange and i've read that the way to do this is with a VBA code, I've seen on some websites how to do it but when I have tried it doesn't seem to work, and as I'm a rather average excel user I think it could be me making the mistakes rather than the code not working, so I would very much appreciate if someone could give me a step by step idiots guide on how to do this.

    Thanks

  2. #2
    Valued Forum Contributor squiggler47's Avatar
    Join Date
    02-17-2009
    Location
    Littleborough, UK
    MS-Off Ver
    Excel 3.0 to 2007+2010! (couldnt get 2.1 working)
    Posts
    1,013

    Re: Sum coloured cells!!!

    It's not reccomended to do it as there are lots of problems with it, if possible its better to test for the value rather than colour, there's a reason excel doesnt provide this function!!!

    these two functions should help if you REALLY have to!!!

    Create a new module, and paste the code in the module

    then in your sheet :

    =SumCellColor(A1,A1:A99) where A1 is a cell of the color you want to sum!


    here is code to count cells of a colour :

    Function CountCellColor(ColorToTest As Range, MyRange As Range) As Long
    
    Dim mycell As Range
    Dim Count As Long
    
    Count = 0
    testcolor = ColorToTest.Interior.ColorIndex
    
    For Each mycell In MyRange
    
        With mycell
            If mycell.Interior.ColorIndex = testcolor Then
                Count = Count + 1
            End If
        End With
    Next
    
    CountCellColor = Count
    
    End Function

    here is code to sum cells of a colour

    Function SumCellColor(ColorToTest As Range, MyRange As Range) As Double
    
    Dim mycell As Range
    Dim Total as Double
    
    
    testcolor = ColorToTest.Interior.ColorIndex
    
    For Each mycell In MyRange
    
        With mycell
            If mycell.Interior.ColorIndex = testcolor Then
                Total=Total+mycell.value
            End If
        End With
    Next
    
    SumCellColor = Total
    
    End Function

+ 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