Share via

count color VB and conditional format

Anonymous
2017-07-02T15:40:12+00:00

Hello,

Can I modify this VB to update when a cell's color is changed to match? It works but I have to select A14 and hit enter.

A13 = color to be counted

A14 =CountCcolor($B$9:$DD$23,A13)

Function CountCcolor(range_data As Range, criteria As Range) As Long

    Dim datax As Range

    Dim xcolor As Long

xcolor = criteria.Interior.ColorIndex

For Each datax In range_data

    If datax.Interior.ColorIndex = xcolor Then

        CountCcolor = CountCcolor + 1

    End If

Next datax

End Function

Can this be modified to count cells that have been conditionally formatted for color

=ISNUMBER(B9) color cells purple

=$B$9:$DB$23

Thanks

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

3 answers

Sort by: Most helpful
  1. Anonymous
    2017-07-02T17:21:00+00:00

    Count numerics only in a cell.

    =SUM(LEN(A1)-LEN(SUBSTITUTE(A1,{1,2,3,4,5,6,7,8,9,0},"")))Gord
    

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2017-07-02T16:41:15+00:00

    Application.Volatile works.

    Is there a count funtion for counting just numbers in a cell without text?  I've searched.  I have cells with numbers and text that I don't want counted.

    Thanks

    Was this answer helpful?

    0 comments No comments
  3. HansV 462.6K Reputation points
    2017-07-02T15:53:24+00:00

    If you add the line

        Application.Volatile

    at the beginning of the function code, Excel will recalculate the function whenever it performs any calculation. Simply changing a color won't trigger a recalculation - Excel doesn't work that way.

    If you want to count conditionally formatted cells, it's better to count based on the condition behind the rule, e.g.

    =COUNT($B$9:$DB$23)

    counts the number of cells with a number value in the range.

    Was this answer helpful?

    0 comments No comments