Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Font colour change based on Rgb codes given in specific cells

I have written the following code to change cell font colour to RGB values
222, 155, 55

Sub CellColourChange()

' Set the font colour of cell G18 to RGB scale from answers in
questionnaire.
Range("G18").Select
Selection.Font.Color = RGB(222, 155, 55)

End Sub

However, I would really like to make this code more advanced, getting the
rgb values from cells (e.g. I18, j18, k18). I tried using
Font.Color = RGB("I18", "j18", "k18") instead of the values I used in the
first version. This clearly does not work. Can anyone tell me how to do this?
I'd appreciate the help a lot.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Font colour change based on Rgb codes given in specific cells

You can do something like

Selection.Font.Color = RGB(Range("I18").Value, Range("J18").Value,
Range("K18").Value)

Note, though that you may not get the exact color you want. Excel is limited
to 56 colors. Those can be any 56 colors you want, but you still get only
56. If you attempt to use a color that is not on Excel's pallet, it will
choose the closest color on the pallet to what you specify. Since the idea
of a "closest" color is rather subjective you may not get the right color.

You could modify the pallet to include your new color:

Dim C As Long
C = RGB(Range("I18").Value, Range("J18").Value, Range("K18").Value)
ThisWorkbook.Colors(56) = C
Selection.Font.ColorIndex = 56


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"greencecil" wrote in message
...
I have written the following code to change cell font colour to RGB values
222, 155, 55

Sub CellColourChange()

' Set the font colour of cell G18 to RGB scale from answers in
questionnaire.
Range("G18").Select
Selection.Font.Color = RGB(222, 155, 55)

End Sub

However, I would really like to make this code more advanced, getting the
rgb values from cells (e.g. I18, j18, k18). I tried using
Font.Color = RGB("I18", "j18", "k18") instead of the values I used in the
first version. This clearly does not work. Can anyone tell me how to do
this?
I'd appreciate the help a lot.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding codes based on a font color Ing Excel Discussion (Misc queries) 1 June 9th 08 09:25 AM
sumif - I wish to add cells based on the font/fill colour Pev Excel Worksheet Functions 3 April 13th 08 12:31 AM
Advanced Conditional Formatting Help Required - Change cell colour based on values of other cells [email protected] Excel Programming 1 February 9th 07 12:24 AM
Change font and background color of several cells based on result of a formula Zenaida Excel Discussion (Misc queries) 2 April 27th 06 06:46 PM
Change the colour of a bunch of cells, based on one cell. Craig & Co. Excel Programming 2 October 14th 04 06:28 AM


All times are GMT +1. The time now is 09:39 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"