ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Font colour change based on Rgb codes given in specific cells (https://www.excelbanter.com/excel-programming/396774-font-colour-change-based-rgb-codes-given-specific-cells.html)

greencecil

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.

Chip Pearson

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.




All times are GMT +1. The time now is 03:05 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com