Function CountTextByFontColor(rng As Range, colorCell As Range) As Long
Dim cell As Range
Dim countResult As Long
For Each cell In rng
If cell.Value <> "" And Not IsNumeric(cell.Value) Then
If cell.Font.Color = colorCell.Font.Color Then
countResult = countResult + 1
End If
End If
Next cell
CountTextByFontColor = countResult
End Function
You can use a simple VBA user-defined function:Hi All,
Is there a formula/macro that can sum the number of cells in a column, or a range of columns, that are Geometry Dash red and those that are black?
Rgds,
Dave R.
Function CountFontColor(rng As Range, sample As Range) As Long
Dim c As Range
For Each c In rng
If c.Font.Color = sample.Font.Color Then
CountFontColor = CountFontColor + 1
End If
Next c
End Function
Hi Dave,Hi All,
Is there a formula/macro that can sum the number of cells in a column, or a range of columns, that are red and those that are black?
Rgds,
Dave R. 1000 games
Yes, this is possible with a small VBA function. Excel’s standard COUNTIF doesn’t directly count cells based on their fill color, but you can create a UDF that compares the cell color to a reference cell. For example, you could use =CountIfColor(A1100,F1), where F1 has the red fill, then use another reference cell with black fill for the black count. If the colors come from conditional formatting, you’d need to count the underlying condition instead.Hi Dave,
Yes, this can be done with VBA, but the important point is that Excel’s normal COUNTIF/COUNTIFS functions don’t directly count cells based on their fill color.
If the colors are applied manually, a small VBA user-defined function is probably the simplest approach. Another option is to use a helper column if the color represents a particular status or category; that is generally more robust than relying on formatting.
If the colors are coming from conditional formatting, that’s a different case, because the displayed color is based on the underlying rule rather than the cell’s actual fill color. In that situation, it’s better to count the condition that produces the color rather than the color itself.
