title: Automatic calculation of Excel VBA UDF related to cell properties
body: <p>I have written an UDF to count cells of certain color and with certain LineStyles, I'm posting the entire function: </p>
  
  <pre><code>Function CountTime(rData As Range, cellRefColor As Range) As Variant    
  
      Dim indRefColor As Long
      Dim cellCurrent As Range
      Dim cntRes As Variant
  
      Application.Volatile
  
      cntRes = 0
      indRefColor = cellRefColor.Cells(1, 1).Interior.Color
      For Each cellCurrent In rData
          If indRefColor = cellCurrent.Interior.Color Then
              cntRes = cntRes + 1
          End If
          If cellCurrent.Borders(xlDiagonalUp).LineStyle &lt;&gt; xlNone Then
              cntRes = cntRes + 0.5
          End If
      Next cellCurrent
  
      CountTime = cntRes
  End Function
  </code></pre>
  
  <p>Now, the problem I have is that the formula does not automatically calculate when one of the cells in <code>rData</code> has it's color or line properties changed. 
  I have added <code>Application.Volatile</code>, and I also tried to trigger the calculation by a <code>Worksheet_Change</code> sub, however that does not work as Excel does not seem to consider changing color a change to the cell/worksheet. </p>
  
  <p>Is there any way to make the cell calculate and update automatically when a user changes the color or line properties of a cell in <code>rData</code>?</p>
  
  <p>EDIT -- SOLVED
  Thanks very much ignotus, the ChangeSelection workaround is good enough for my purposes. Didn't think of that.
  And the background info is also handy, thanks a lot. </p>