Hi Avner ,
As already stated by Chip you can do that in a Function, but Chip
has a page on explaining the difference(s) between a Function
and a SUB.
"Macros as Opposed to Functions" as seen in his index
http://www.cpearson.com/excel/topic.htm
but the actual page is
Macros And Functions
http://www.cpearson.com/excel/differen.htm
I have a page on color, and as previously stated by Bob Phillips
you will be wanting to us Color Index values instead of RGB.
Color Palette and the 56 Excel ColorIndex Colors
http://www.mvps.org/dmcritchie/excel/colors.htm
Somethings can be done in Conditional Formatting
http://www.mvps.org/dmcritchie/excel/condfmt.htm
and where Conditional Formatting can't be used because
of the limitation of 3 colors (conditions) you can use an
Event Macro.
http://www.mvps.org/dmcritchie/excel/event.htm#case
From what you supplied, perhaps you want something like:
Sub ColorMe_37()
ActiveCell.Interior.ColorIndex = 37
End Sub
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages:
http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page:
http://www.mvps.org/dmcritchie/excel/search.htm
"Avner Mediouni" wrote in message ...
I would like to write a function that will color the interior of a cell
according to RGB values.
This is my code:
Function InteriorColor(ByVal R as Integer, ByVal G as Integer, ByVal B as
Integer)
ActiveCell.Interior.Color = RGB(R, G, B)
End Function
This simple code refuse to work when I call it from a worksheet, although it
works well when activates him from another subroutine.
What is wrong ?!!
Thanks for the help
Avner
R&D Physicist
email: