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
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

You can do something like

Selection.Font.Color = RGB(Range("I18").Value, Range("J18").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

Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
(email on the web site)

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question