Coloring cells thru VBA
Hi
if this code is within a user defined function it won't work. Within
UDFs you cannot change the Excel environment (that is change the
format, etc).
You can only return values.
--
Regards
Frank Kabel
Frankfurt, Germany
Lawrence Mak wrote:
I was working on a function that calculates the average
value of a range of cells. If the average amounts to
zero, I want to change either the cell background to a
particular color to alert users. I tried this in VBA:
If Occupancy = 0 Then
ActiveCell.Interior.Color= RGB(255, 0, 0)
End If
Where Occupancy is the name of the function. However this
doesn't work as expected and the cell's color remains
unchanged. Yet the same command works perfectly through
the immediate window. Can anyone explain why it doesn't
work and how to rectify it? Thanks
|