Summing marked cells

  • Thread starter Thread starter Sam
  • Start date Start date
S

Sam

I need to include "marked" cells in a formula. Ideally,
when a cell is shaded a color or marked in a similar
manner, this would cause the cell to be included in a
formula. For instance, three cells with the number 50 in
each. Two of the cells are "marked/shaded with a color" -
if the three cells were included in a summation formula,
the output would be 100. Any help would be appreciated.
 
Sam,

This will work, but is the long way about it:

Sub sumMarked()
i = 0
If Range("A1").Interior.Color = vbYellow Then
i = i + Range("A1").Value
End If
If Range("A2").Interior.Color = vbYellow Then
i = i + Range("A2").Value
End If
If Range("A3").Interior.Color = vbYellow Then
i = i + Range("A3").Value
End If
If Range("A4").Interior.Color = vbYellow Then
i = i + Range("A4").Value
End If
If Range("A5").Interior.Color = vbYellow Then
i = i + Range("A5").Value
End If
Range("A6").Value = i

End Sub

What you could do is define the range and loop through
it, checking the Interior.Color.

Jill
 
Back
Top