Sum all cells with interior color...

C

Ctech

Hi

I'm trying to make a macro which will sum all the cells which have a
special interior color.

However I don't know how to sum these cells. I will also need to check
if the Cell contains a number (ISNUMBER).

Do anyone know how I can do this,

As always thanks.


For Each Cell In Selection
On Error Resume Next
If Cell.Interior.ColorIndex = 36 Then
If Cell = ISNUMBER then
End if


End If

Next Cell
 
N

Norman Jones

Hi Ctech,

Try:

'=============>>
Public Sub Tester091()
Dim rng As Range
Dim rCell As Range
Dim myVal As Double

Set rng = Selection

For Each rCell In rng.Cells
If rCell.Interior.ColorIndex = 36 Then
If Application.IsNumber(rCell.Value) Then
myVal = myVal + rCell.Value
End If
End If
Next rCell

MsgBox myVal

End Sub
'<<=============
 
Y

Yngve

Hi Ctect

this should work
Sub b()

Dim p As Double
p = 0
For Each cell In Selection
On Error Resume Next
If cell.Interior.ColorIndex = 36 Then
If IsNumeric(cell) Then
p = p + cell.Value
End If


End If


Next cell

end sub

Regards Yngve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top