• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Have a UDF active when the workbook is open.

OK, I have this code that counts cell colors. It is in a module. What I want to do is on the worksheet where the function will be used is to have it active so when the user changes a color in a range of specified cells the function automatically runs. Much like if you have COUNT or SUM in a range and change a number, it auto calculates.

At this time, the UDF only works when you re-enter it in a cell. Basically I want the UDF active all the time.

Code:
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
 
Back
Top