Setting ActiveCell color

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've a simple function, copied from various examples on the net, to sum
numbers based on the color of another cell. I want change the active cell
color but it doesn't seem to work. Any suggestions, any help appreciated,
code is as follows...

Function ColorSum(cRefColor, rRange)
Dim r As Range
Dim iColorIndex As Integer

ColorSum = 0

iColorIndex = cRefColor.Font.ColorIndex

'build formula for range
For Each C1 In rRange.Cells
If C1.Font.ColorIndex = iColorIndex Then
ColorSum = ColorSum + C1.Value
Else
C1.Font.ColorIndex = iColorIndex
End If
Next

'this doesn't work!
ActiveCell.Font.ColorIndex = iColorIndex

End Function
 
It won't work if you are calling the function from a worksheet cell.
Functions called from worksheet cells cannot change any part of the Excel
environment, including changing the attributes of cells.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top