PC Review


Reply
Thread Tools Rate Thread

Cell background color (interior color) setting not working

 
 
Martin E.
Guest
Posts: n/a
 
      21st May 2006
I am having a problem getting this to work and would appreciate your input.


In "Module1":


Function SetBackgroundColor(Parameter As Range) As String
Dim xlRange As Range

SetBackgroundColor = ""

If (TypeName(Application.Caller) = "Range") Then
Set xlRange = Application.Caller
xlRange.Interior.Color = ValueToRGB(CInt(Parameter.Value))
End If

End Function

Here "ValueToRGB" simply has a Select Case statement that outputs specific
RGB (long) values based on input. This function works well and has been
verified.

The problem is that "SetBackgroundColor" never changes the background color
of the target cell.

I've even tried such code as:

[A1].Interior.Color = ValueToRGB(1)


[A2].Interior.Color = ValueToRGB(2)


[A3].Interior.Color = ValueToRGB(3)

to no avail.

However, if the above three lines are place into a public Sub that is called
by hand (By executing the macro via ALT-F8 (Tools/Macro/Macros) all three
cells are colorized perfectly.

For some reason setting the interior color does not work from a user
function, regardless of whether the target is the function within which the
function is being called or an entirely different (even hard-coded, rather
than passed or calculated) cell.

Any ideas?

Thanks,

-Martin



 
Reply With Quote
 
 
 
 
Tom Ogilvy
Guest
Posts: n/a
 
      21st May 2006
That is correct. A function used in a worksheet can not alter the excel
environment. It can only return a value to the cell where it is located.

--
Regards,
Tom Ogilvy

"Martin E." <0_0_0_0_@pacbell.net> wrote in message
news:uO1cg.29951$(E-Mail Removed)...
> I am having a problem getting this to work and would appreciate your

input.
>
>
> In "Module1":
>
>
> Function SetBackgroundColor(Parameter As Range) As String
> Dim xlRange As Range
>
> SetBackgroundColor = ""
>
> If (TypeName(Application.Caller) = "Range") Then
> Set xlRange = Application.Caller
> xlRange.Interior.Color = ValueToRGB(CInt(Parameter.Value))
> End If
>
> End Function
>
> Here "ValueToRGB" simply has a Select Case statement that outputs specific
> RGB (long) values based on input. This function works well and has been
> verified.
>
> The problem is that "SetBackgroundColor" never changes the background

color
> of the target cell.
>
> I've even tried such code as:
>
> [A1].Interior.Color = ValueToRGB(1)
>
>
> [A2].Interior.Color = ValueToRGB(2)
>
>
> [A3].Interior.Color = ValueToRGB(3)
>
> to no avail.
>
> However, if the above three lines are place into a public Sub that is

called
> by hand (By executing the macro via ALT-F8 (Tools/Macro/Macros) all three
> cells are colorized perfectly.
>
> For some reason setting the interior color does not work from a user
> function, regardless of whether the target is the function within which

the
> function is being called or an entirely different (even hard-coded, rather
> than passed or calculated) cell.
>
> Any ideas?
>
> Thanks,
>
> -Martin
>
>
>



 
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
How to make font color oppose to cell interior color narke Microsoft Excel Discussion 4 31st May 2010 03:11 AM
Setting a cell background color SteelAdept Microsoft Excel Programming 6 28th Nov 2008 03:58 AM
Problem in setting Cell Interior Color filling. =?Utf-8?B?VmVua2F0YWNoYWxhbQ==?= Microsoft Excel Programming 1 29th Sep 2004 07:13 PM
Setting Cell background color using an IF statememnt Rob Microsoft Excel Worksheet Functions 3 28th Jul 2004 07:36 PM
Setting cell background color based on value =?Utf-8?B?RXJpaw==?= Microsoft Excel Programming 3 25th Feb 2004 10:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:04 PM.