Quote:
Originally Posted by g-bebe
I'm making a spreadsheet and want to use coloured backgrounds for individual cells to make things easier to read. Only using two colours: green (right) and red (wrong) obv. Is there a way in Excel to calc how many cells ina given column/row are green (or red)?
You can use a UDF (user-defined function)
1. Right click on a sheet tab > view code
2. On the far left, right click on VBA Project > Insert > Module
3. Paste the following
Code:
Public Function countInteriors(currentRange As Range, interiorColor As Integer) As Integer
Dim curCount As Integer
Dim ce As Range
curCount = 0
For Each ce In currentRange
If ce.Interior.ColorIndex = interiorColor Then
curCount = curCount + 1
End If
Next ce
countInteriors = curCount
End Function
Public Function colorIndex(currentCell As Range) As Integer
colorIndex = currentCell.Interior.colorIndex
End Function
4. Go back to your worksheet and then you can do =countInteriors(A1:A100,3)
5. Where A1:A100 is the range and 3 in the color index
6. to find the colorindex you can use the other function =colorIndex(A1)
Hope there's enough their for you to use