Colours in Vba
Colours in Vba
COLOURS IN VBA
Excel Colours
Excel VBA has a surprisingly large number of ways to change the colours of various objects. This
chapter briefly summarises the main techniques using the fill colour of a cell as an example.
There are two properties that you can change to affect the fill colour of a range object, as shown in
the diagram below:
The table below summarises the differences between the two properties:
ActiveCell.Interior.ColorIndex = xlColorIndexNone
You can view a workbook’s ColorIndex colours by choosing File | Options from the Excel ribbon.
The Color property has 16,777,216 different values! Fortunately, you don’t need to remember
which number represents which colour as there are several sets of named colours in Excel VBA.
VBA has eight generic colour constants which you can use in any Office application.
Excel has its own specific list of named colours, all of which begin with the letters rgb.
The RGB function allows you to calculate the number of any colour by mixing different amounts of
red, green and blue. This is a common technique used by companies to define brand colours.