Forum Discussion
Colouring a cell with a calculated colour
Hi,
I need to colour a cell with a color calculated from its RGB components or defined by its hexadecimal code.
Simple conditional formatting seems not to be usable for that, as it allows only a choice between a limited number of predefined colors.
I haven't seen any information on this anywhere.
Is it possible and how could I make it?
I'm using Excel for Mac 2011 version 14.7.0 on a MacBookPro under macOS High Sierra 10.13.6, but I think/hope that my question is a generic one and not dependant on the environment.
Thanks in advance for any help on this issue.
Gerard
--
- Hi, Have a look at this web page, seems to have what your looking for, https://stackoverflow.com/questions/1426369/excel-set-background-colour-of-cell-to-rgb-value-of-data-in-cell
3 Replies
- Rich99Iron ContributorHi, Have a look at this web page, seems to have what your looking for, https://stackoverflow.com/questions/1426369/excel-set-background-colour-of-cell-to-rgb-value-of-data-in-cell
- GFontaineCopper Contributor
Rich99 wrote:
Hi, Have a look at this web page, seems to have what your looking for, https://stackoverflow.com/questions/1426369/excel-set-background-colour-of-cell-to-rgb-value-of-data-in-cell
Great Rich99 , thanks a lot, this link seems to fit exactly what I want to do.My understanding is that this Web page proposes two different methods, one based on VBA, the other one based on Macros.
I am not familiar with any of them but I will try and learn!
Do you have any advice about which one to try first?
Best,
Gerard
--
- GFontaineCopper Contributor
Good news:
My tests are going very well: I have been able to run successfully the Excel Macro:
Sub Colourise()
'
' Colourise Macro
'
' Colours all selected cells, based on their current integer rgb value
' For e.g. (it's a bit backward from what you might expect)
' 255 = #ff0000 = red
' 256*255 = #00ff00 = green
' 256*256*255 #0000ff = blue
' 255 + 256*256*255 #ff00ff = magenta
' and so on...
'
' Keyboard Shortcut: Ctrl+Shift+C (or whatever you want to set it to)
'
For Each cell In Selection
If WorksheetFunction.IsNumber(cell) Then
cell.Interior.Color = cell.Value
End If
Next cell
End SubBUT one has to be very cautious with the input data as (at least with my version) Excel processes the colour value as "BGR" as explained in the code, and not "RGB" as I was expecting!
The Cell content has to be: (Blue*256+Green)*256+Red to get the right colour!!!
Gerard
--