• 466K Members
• 9,141 Online
• 563K Conversations
SOLVED

New Contributor

# 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

--

3 Replies
Solution

# Re: Colouring a cell with a calculated colour

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

# Re: Colouring a cell with a calculated colour

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

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!

Best,

Gerard

--

# Re: Colouring a cell with a calculated colour

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 Sub

BUT 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

--

Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
46 Replies
Extentions Synchronization
Deleted in Discussions on
3 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
30 Replies
Security Community Webinars
Valon_Kolica in Security, Privacy & Compliance on
13 Replies
flashing a white screen while open new tab
Deleted in Discussions on
14 Replies