Thursday, 23 March 2017

Code : SumByColor

Function SumByColor(CellColor As Range, rRange As Range) 
Dim cSum As Long 
Dim ColIndex As Integer 
ColIndex = CellColor.Interior.ColorIndex 
For Each cl In rRange 
  If cl.Interior.ColorIndex = ColIndex Then 
    cSum = WorksheetFunction.SUM(cl, cSum) 
  End If 
Next cl 
SumByColor = cSum 
End Function

14 comments:

  1. how to Subtraction with background color

    ReplyDelete
  2. ive trying to calculate a duration between time using this method, its failed.. its only works on number, not working for time,..
    example:
    1) 1 hour 5 min -yellow
    2) 1 hour - yellow
    3) 30 min - green

    can you show me how can i get the value based on date/time?

    thanks
    Don

    ReplyDelete
  3. Hello

    Very useful video thanks.



    ReplyDelete
  4. I have use above code but no sum of amount that have decimal , any idea to sum it

    ReplyDelete
  5. Thanks for the code, it's very helpful.

    ReplyDelete
  6. Thank you very much. Very clever and useful. Well done.

    ReplyDelete
  7. WHY IS IT ROUNDING OFF MY FIGURES

    ReplyDelete
  8. why decimal not displayed???

    ReplyDelete
  9. very useful. thanks!

    ReplyDelete
  10. It´s really helpful. THANKS

    ReplyDelete
  11. When I reopen the file and update, its showing #NAME? instead of figger. Can you fix this please?

    ReplyDelete
  12. Hi it's very useful and helpful Thanks.
    But it's not sum if there's decimal means 0.5 or 1.5 Please give some ideas or update the codes for that
    Thanks for this great work

    ReplyDelete