Cell color

Closed
Doc1772 - Mar 24, 2015 at 11:39 AM
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 - Mar 24, 2015 at 12:16 PM
Hello,

I have a worksheet with various dollar values in it. I want to write a formula to add all the cells that are a certain color (green or yellow). If I change the color to green I want that value added to a summation box. Any ideas?

1 response

TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 552
Mar 24, 2015 at 12:16 PM
Hi Doc,

The following code will look in column A for green and yellow filled cells.
The values of the green filled cells will be added and the result will be placed in B1. The result for the yellow filled cells will be placed in B2.

Here is the code:
Sub RunMe()
Dim lRow As Integer
Dim GreenCount, YellowCount As Long

lRow = Range("A" & Rows.Count).End(xlUp).Row

For Each cell In Range("A1:A" & lRow)
    If cell.Interior.Color = 5287936 Then GreenCount = GreenCount + cell.Value
    If cell.Interior.Color = 65535 Then YellowCount = YellowCount + cell.Value
Next cell

Range("B1").Value = GreenCount
Range("B2").Value = YellowCount
End Sub


Best regards,
Trowa
0