Excel

TheSmallman.com

an XL ideas Lab

Dashboards VBA
  • Home
  • Dashboards
    • Tips & Tricks
    • Charts
    • Modelling
    • Infographics
    • VBA
  • Shop Dashboards
    • Power Pivot a User Guide
    • Excel Dashboard Course
    • Advanced Dashboard Course
    • Financial Modelling Course
    • Excel VBA Course
  • Blog
  • About
Menu

Excel Dashboards VBA

Street Address
City, State, Zip
Phone Number
an XL ideas Lab

Your Custom Text Here

Excel Dashboards VBA

  • Home
  • Dashboards
  • Excel Tips
    • Tips & Tricks
    • Charts
    • Modelling
    • Infographics
    • VBA
  • Shop Dashboards
  • PowerPivot
    • Power Pivot a User Guide
  • Courses
    • Excel Dashboard Course
    • Advanced Dashboard Course
    • Financial Modelling Course
    • Excel VBA Course
  • Blog
  • About

Red, Green, Blue Interior Cell Colour

January 24, 2016 Marcus Small

Recently I was giving a half day course on heat maps and came up with the novel idea of creating a custom function which would identify the primary colour scheme for a cells interior colour.  It is in an effort to save a little time in the creation of a colour scheme for heat mapping.  Rather than laying down the colour and looking up the Red, Green and Blue numerical combination I simply lay the colour down and the custom function does the work for me.  

Red for example has a (Red, Green, Blue) number which is Red 255, Green 0, Blue 0.  This can be used to generate the colour of a shape based on criteria. You will see plenty of examples on this site when using heat maps.  You set up a table which ranks achievement to a given plan then colour your map based on that achievement which is represented by a colour.  You might use a traffic light set up where Red is under achievement and Green is beating target, with yellow somewhere around par.  The following is the custom functions which will split out the cells interior colour into its numerical representation.

Function Red(rng) As Long
Dim c As Long
Dim r As Long
c = rng.Interior.Color
r = c Mod 256
Red = r
End Function

Function Green(rng) As Long
Dim c As Long
Dim g As Long
c = rng.Interior.Color
g = c \ 256 Mod 256
Green = g
End Function

Function Blue(rng) As Long
Dim c As Long
Dim b As Long
c = rng.Interior.Color
b = c \ 65536 Mod 256
Blue = b
End Function

If the cell you were wanting to test were in A2 you would apply the formula as follows:

B2=Red(A2)

C2=Green(A2)

D2=Blue(A2)

The colour scheme for cell A2 would be revealed and could be used to generate the back ground colour for a particular shape in Excel.

Tags VBA, Custom Function, Red green blue, Excel, Spreadsheet, colour scheme, color
← VBA Check if Sheet ExistsCopy and Paste an Excel Chart into PowerPoint with VBA →

Featured Posts

Excel Dashboards: Tracking a Crisis

Excel Dashboards: Tracking a Crisis
April 14, 2020

Recent Posts

Populating an Excel Table from a Range of Cells with VBA

Populating an Excel Table from a Range of Cells with VBA June 12, 2025

Fuzzy Distribution with Randbetween

Fuzzy Distribution with Randbetween May 21, 2025

Add Minimum and Maximum for Chart in Cells

Add Minimum and Maximum for Chart in Cells March 12, 2025

Inflation Over Multiple Years in a Single Cell

Inflation Over Multiple Years in a Single Cell January 10, 2025

Hubspot Dashboard

Hubspot Dashboard October 3, 2024

Monthly Dashboard With Supporting Metrics

Monthly Dashboard With Supporting Metrics September 25, 2024

Excel Show Missing Sheet Tabs

Excel Show Missing Sheet Tabs July 29, 2024

Run Macro Overnight Automatically

Run Macro Overnight Automatically June 24, 2024

Split File into Parts and Save to Directory

Split File into Parts and Save to Directory April 20, 2024

Most Popular Author

Most Popular Author December 14, 2023

 

Follow US:

 
 

MarcusSmall@thesmallman.com

 

TheSmallman.com - Making your small systems hum...
© Copyright 2013-2024 theSmallman.com All Rights Reserved.