Adding cells with specific colors

S

spanishjon

*I have created a table full of numbers ranging several rows and column
(eg A1:A10), I would like to add up in an adjacent cell all thos
numbers that I have highlighted in yellow (i.e. whose cell I hav
changed the background to yellow). Ideally, I would like to be able t
change which of these numbers is highlighted and the adjacent cell t
change its sum respectively.
I am an intermediate in Excel and beginner in VBA so please go slow :
I would appreciate any ideas. Thank you!!* ;
 
L

L. Howard Kittle

Hi Jon,

Give this a try. Name your cells DataY and run this macro. It will sum the
value of the yellow cells and display the total in F1 and in a message box.
Note: The cells color cannot be the result of conditional formatting.

Sub SumColorCountYellow()
Dim Yellow6 As Integer
Dim Cell As Range

For Each Cell In Range("DataY")
If Cell.Interior.ColorIndex = 6 Then
Yellow6 = Yellow6 + Cell.Value
End If
Next

Range("F1").Value = "Yellow = " & Yellow6

MsgBox " Yellow adds to " & Yellow6, _
vbOKOnly, "CountColor"

Range("F1").Value = ""
End Sub

HTH
Regards,
Howard
 
S

spanishjon

Thank you for the macro Howard, it really helped me. Exactly what Iwa
looking for
 
Top