PC Review


Reply
Thread Tools Rate Thread

Changing cell color from a function

 
 
Andy
Guest
Posts: n/a
 
      24th May 2007
I have created a fairly simple function that will effectively cycle a number
from 1 to 288 then back to 0.
It works fine.
The function will be applied to around 1000 cells.

In addition to the roll oevr I now want to indicate that roll-over has
occurred by changing the fill-color of the cell.
It does not seem to work

I have copied the same cell-changing code :-

Worksheets("Scheduled Servicing").Range("G44").Interior.ColorIndex =
3
Worksheets("Scheduled Servicing").Range("g44").Interior.Pattern =
xlSolid

to a subroutine and it works fine. If I call the subroutine from the
function it does not color the cell

I am beginning to get the feeling that a function cannot change the color of
a cell even via a subroutine. Is this correct?
If so how can I cange the color of the cell? Conditional formatting is out
as the requirements for color changing may end up be very complex.

Many Thanks in advance

Andy


 
Reply With Quote
 
 
 
 
Ron Rosenfeld
Guest
Posts: n/a
 
      24th May 2007
On Thu, 24 May 2007 14:35:31 +0100, "Andy"
<(E-Mail Removed)> wrote:

>I have created a fairly simple function that will effectively cycle a number
>from 1 to 288 then back to 0.
>It works fine.
>The function will be applied to around 1000 cells.
>
>In addition to the roll oevr I now want to indicate that roll-over has
>occurred by changing the fill-color of the cell.
>It does not seem to work
>
>I have copied the same cell-changing code :-
>
> Worksheets("Scheduled Servicing").Range("G44").Interior.ColorIndex =
>3
> Worksheets("Scheduled Servicing").Range("g44").Interior.Pattern =
>xlSolid
>
>to a subroutine and it works fine. If I call the subroutine from the
>function it does not color the cell
>
>I am beginning to get the feeling that a function cannot change the color of
>a cell even via a subroutine. Is this correct?


Yes

>If so how can I cange the color of the cell? Conditional formatting is out
>as the requirements for color changing may end up be very complex.



You might be able to use an event triggered macro -- a frequent work-around
when more than three or four conditional formats are required.

--ron
 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      24th May 2007
Private Sub Worksheet_Calculate()
If ActiveCell > 1 Then ActiveCell.Interior.ColorIndex = 6
End Sub
to get fancier, use a select case for multiple choices
Private Sub Worksheet_Calculate()
'If ActiveCell > 1 Then ActiveCell.Interior.ColorIndex = 6
ActiveCell.Interior.ColorIndex = 0
Select Case ActiveCell
Case Is > 10: x = 3
Case Is > 5: x = 6
'etc
Case Else
End Select
ActiveCell.Interior.ColorIndex = x
End Sub

--
Don Guillett
SalesAid Software
(E-Mail Removed)
"Andy" <(E-Mail Removed)> wrote in message
news:4655913b$(E-Mail Removed)...
>I have created a fairly simple function that will effectively cycle a
>number from 1 to 288 then back to 0.
> It works fine.
> The function will be applied to around 1000 cells.
>
> In addition to the roll oevr I now want to indicate that roll-over has
> occurred by changing the fill-color of the cell.
> It does not seem to work
>
> I have copied the same cell-changing code :-
>
> Worksheets("Scheduled Servicing").Range("G44").Interior.ColorIndex
> = 3
> Worksheets("Scheduled Servicing").Range("g44").Interior.Pattern =
> xlSolid
>
> to a subroutine and it works fine. If I call the subroutine from the
> function it does not color the cell
>
> I am beginning to get the feeling that a function cannot change the color
> of a cell even via a subroutine. Is this correct?
> If so how can I cange the color of the cell? Conditional formatting is out
> as the requirements for color changing may end up be very complex.
>
> Many Thanks in advance
>
> Andy
>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing the color of a cell based on the color of another cell. LATC Microsoft Excel Misc 6 4th Dec 2009 09:49 PM
Changing Cell Background Color based on data from another cell Speedy Microsoft Excel Misc 2 16th Mar 2009 04:10 PM
Changing a cell color inside a function called by that cell Wayne Erfling Microsoft Excel Programming 8 29th Jan 2007 01:55 AM
Cell colors or text color changing when date in cell gets closer. =?Utf-8?B?Q2hhc2U=?= Microsoft Excel Worksheet Functions 5 19th Oct 2006 08:57 AM
Excel VBA-Changing cell color with if then function red5 Microsoft Excel Programming 2 23rd Jul 2004 05:07 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:12 PM.