View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Lawrence Mak Lawrence Mak is offline
external usenet poster
 
Posts: 2
Default Coloring cells thru VBA

Hi Frank,

Thanks for the advice. Do you think there are any
workarounds?

Lawrence Mak
-----Original Message-----
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


.