VBA RGB Colour Name

Biz

Well-known Member
Joined
May 18, 2009
Messages
1,773
Office Version
  1. 2021
Platform
  1. Windows
Dear All,

Is there VBA code which can give colour name based on RGB (232,241,209)?

Your help would be greatly appreciated.

Kind Regards,

Biz
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
NO, not from what I can see. I guess you could always dimension the colour as a variable so you can specify your own name as CamelKhaki or something like that.
 
Upvote 0
Short answer is No, but you could use

Code:
Sub MM1()
Sheet2.Activate
PB = RGB(232, 241, 209)
Range("A1").Interior.Color = PB
End Sub
 
Upvote 0
Here are some that I have used in the past.
Code:
'http://vbaexpress.com/forum/showthread.php?t=22084
Public Enum xlColorIndex
    xlCIBlack = 1
    xlCIWhite = 2
    xlCIRed = 3
    xlCIBrightGreen = 4
    xlCIBlue = 5
    xlCIYellow = 6
    xlCIPink = 7
    xlCITurquoise = 8
    xlCIDarkRed = 9
    xlCIGreen = 10
    xlCIDarkBlue = 11
    xlCIDarkYellow = 12
    xlCIViolet = 13
    xlCITeal = 14
    xlCIGray25 = 15
    xlCIGray50 = 16
    xlCIPeriwinkle = 17 '-----------------------------
    xlCIPlum = 18 ' chart colours
    xlCIIvory = 19 '
    xlCILightTurquoiseChart = 20 '
    xlCIDarkPurpleChart = 21 '
    xlCICoralChart = 22 '
    xlCIOceanBlueChart = 23 '
    xlCIIceBlueChart = 24 '
    xlCIDarkBlueChart = 25 '
    xlCIPinkChart = 26 '
    xlCIYellowChart = 27 '
    xlCITurquoiseChart = 28 '
    xlCIVioletChart = 29 '
    xlCIDarkRedChart = 30 '
    xlCITealChart = 31 '
    xlCIBlueChart = 32 '-----------------------------
    xlCISkyBlue = 33
    xlCILightGreen = 35
    xlCILightYellow = 36
    xlCIPaleBlue = 37
    xlCIRose = 38
    xlCILavender = 39
    xlCITan = 40
    xlCILightBlue = 41
    xlCIAqua = 42
    xlCILime = 43
    xlCIGold = 44
    xlCILightOrange = 45
    xlCIOrange = 46
    xlCIBlueGray = 47
    xlCIGray40 = 48
    xlCIDarkTeal = 49
    xlCISeaGreen = 50
    xlCIDarkGreen = 51
    xlCIBrown = 53
    xlCIIndigo = 55
    xlCIGray80 = 56
End Enum


Const cBlack = &H0    '0
Const ciBlack = 1
Const cDarkRed = &H80 '128
Const ciDarkRed = 9
Const cRed = &HFF     '255
Const ciRed = 3
Const cPink = &HFF00FF '16711935
Const ciPink = 7
Const cRose = &HCC99FF '13408767
Const ciRose = 38
Const cBrown = &H3399 '13209
Const ciBrown = 53
Const cOrange = &H66FF '26367
Const ciOrange = 46
Const cLightOrange = &H99FF '39423
Const ciLightOrange = 45
Const cGold = &HCCFF  '52479
Const ciGold = 44
Const cTan = &H99CCFF '10079487
Const ciTan = 40
Const cOliveGreen = &H3333 '13107
Const ciOliveGreen = 52
Const cDarkYellow = &H8080 '32896
Const ciDarkYellow = 12
Const cLime = &HCC99 '52377
Const ciLime = 43
Const cYellow = &HFFFF '65535
Const ciYellow = 6
Const cLightYellow = &H99FFFF '10092543
Const ciLightYellow = 36
Const cDarkGreen = &H3300 '13056
Const ciDarkGreen = 51
Const cGreen = &H8000 '32768
Const ciGreen = 10
Const cSeaGreen = &H669933 '6723891
Const ciSeaGreen = 50
Const cBrightGreen = &HFF00 '65280
Const ciBrightGreen = 4
Const cLightGreen = &HCCFFCC '13434828
Const ciLightGreen = 35
Const cDarkTeal = &H663300 '6697728
Const ciDarkTeal = 49
Const cTeal = &H808000 '8421376
Const ciTeal = 14
Const cAqua = &HCCCC33 '13421619
Const ciAqua = 42
Const cTurquoise = &HFFFF00 '16776960
Const ciTurquoise = 8
Const cLightTurquoise = &HFFFFCC '16777164
Const ciLightTurquoise = 34
Const cDarkBlue = &H800000 '8388608
Const ciDarkBlue = 11
Const cBlue = &HFF0000 '16711680
Const ciBlue = 5
Const cLightBlue = &HFF6633 '16737843
Const ciLightBlue = 41
Const cSkyBlue = &HFFCC00 '16763904
Const ciSkyBlue = 33
Const cPaleBlue = &HFFCC99 '16764057
Const ciPaleBlue = 37
Const cIndigo = &H993333 '10040115
Const cBlueGray = &H996666 '10053222
Const ciBlueGray = 47
Const cViolet = &H800080 '8388736
Const ciViolet = 13
Const cPlum = &H6697881 '6697881
Const ciPlum = 54
Const cLavender = &HFF99CC '16751052
Const ciLavender = 39
Const cGray90 = &H333333 '3355443
Const ciGray90 = 56
Const cGray50 = &H808080 '8421504
Const ciGray50 = 16
Const cGray40 = &H969696 '9868950
Const ciGray40 = 48
Const cGray25 = &HC0C0C0 '12632256
Const ciGray25 = 15
Const cWhite = &HFFFFFF '16777215
Const ciWhite = 2
Const cPeriwinkle = &HFF9999 '16751001
Const ciPeriwindle = 17
Const cIvory = &HCCFFFF '13434879
Const ciInvory = 19
Const cDarkPurple = &H660066 '6684774
Const ciDarkPurple = 21
Const cCoral = &H8080FF '13395456
Const ciCoral = 22
Const cOceanBlue = &HCC6600 '13395456
Const ciOceanBlue = 23
Const cIceBlue = &HFFCCCC '16764108
Const ciIceBlue = 24

Const cColor18 = &H663399 '6697881
Const ciColor18 = 18
Const cColor20 = &HFFFFCC '16777164
Const ciColor20 = 20
Const cColor25 = &H800000 '8388608
Const ciColor25 = 25
Const cColor26 = &HFF00FF '16711935
Const ciColor26 = 26
Const cColor27 = &HFFFF '65535
Const ciColor27 = 27
Const cColor28 = &HFFFF00 '16776960
Const ciColor28 = 28
Const cColor29 = &H800080 '8388736
Const ciColor29 = 29
Const cColor30 = &H80 '128
Const ciColor30 = 30
Const cColor31 = &H808000 '8421376
Const ciColor31 = 31
Const cColor32 = &HFF0000 '16711680
Const ciColor32 = 32
Const ciNone = xlColorIndexNone
Const cNone = xlNone
 
Upvote 0
In the Object Browser, the xlrgbColor constants are being depreciated (e.g. xlrgbAquamarine) but the ColorConstants (e.g. vbRed, vbMagenta) are still being supported.
 
Last edited:
Upvote 0
Thank you very much for your help, everyone. It would have been awesome if I can get RGB colour name.

Biz
 
Upvote 0
It would have been awesome if I can get RGB colour name.

But wouldn't that mean a name for every RGB colour available - an amazing 16,777,216 i.e. 256 x 256 x 256!! No way.

What are you trying to do?
 
Upvote 0
Dear All,

Is there VBA code which can give colour name based on RGB (232,241,209)?

Your help would be greatly appreciated.

Kind Regards,

Biz
Yes! And what's more, you can name it yourself, too. Here's how:
Code:
[COLOR=#008000]' At [B]Procedure [/B]level you can declare a constant like this:[/COLOR]
Sub ColorDeclaration()
    Const CamelKhaki As Long = 13758952 'RGB(232, 241, 209)
    ActiveCell.Interior.Color = CamelKhaki
End Sub
Code:
[COLOR=#008000]' At [B]module [/B]level you can declare a constant like this:[/COLOR]
    Const CamelKhaki As Long = 13758952 'RGB(232, 241, 209)
Sub ColorDeclaration()
    ActiveCell.Interior.Color = CamelKhaki
End Sub
Code:
[COLOR=#008000]
' At [B]Project [/B]level you can declare a constant like this:[/COLOR]
Public Const CamelKhaki As Long = 13758952 'RGB(232, 241, 209)
Sub ColorDeclaration()
    ActiveCell.Interior.Color = CamelKhaki
End Sub
To find the long colour number you can use the immediate window [Ctrl]+[G] by typing:
Code:
?RGB(232, 241, 209)
[Enter] Which produces the identifying long number out of the 16.7 million+ colours available or output it to a msgbox, but that's not so easy to copy into your code...

As far as I can tell there are only about 528 colours in hardcoded into Excel VBA that are CONSTants (means you can create your own that are not hard-coded but leaves you more than 16.7 million options to choose from the RGB palette There are several ways to do this but from Excel 2007 to 2016 the options of using the following code will make you aware of a greater number:
Code:
    ActiveCell.Interior.Color = XlRgbColor.[rgb{color_name}] ' Press ctrl+space to activatre the intellisense feature of VBA
 
Last edited:
Upvote 0
@Kenneth Hobson
user-offline.png

Thanks for the color names and List of Numbers.
I would like to prepare a sheet with the xlrgbcolor names & colors.
My WorkBook is Colors.xls
I have two Sheets.
One is 'xlrgbcolor' in which I have the list of xlrgbcolor names. This is source Sheet.
In this Sheet I have xlrgbcolour names in column B.
I got these names from https://docs.microsoft.com/en-us/office/vba/api/excel.xlrgbcolor
In this list there are 142 xlrgbcolor names.
Another sheet is 'Report' in which I want to populate the cells with the colours using the following code.
Code:
Private Sub cmdInteriorRGB_Click()
 Dim Src As Worksheet 'Colour Names
 Dim Rpt As Worksheet 'Colours
 Set Src = Sheets("xlrgbcolor")
 Set Rpt = Sheets("Interior-RGB")
 Src.Select
 Dim LstRow As Long
 LstRow = Src.Cells(Rows.Count, "B").End(xlUp).Row
 Rpt.Select
 Dim RowNm As Integer
 RowNm = 1
 Rpt.Range("a" & LTrim(str(RowNm))).Select
 Selection.Value = "SlNo"
 Selection.Offset(0, 1).Value = "XLRGB_NAME"
 Selection.Offset(0, 2).Value = "XLRGB_INTR_CLR"
 Dim NowXlClr  As xlRgbcolor
 Do While RowNm <= LstRow
  Selection.Offset(LTrim(str(RowNm)), 0).Value = RowNm
  Selection.Offset(LTrim(str(RowNm)), 1).Value = Src.Range("B" & LTrim(str(RowNm + 1))).Value '"rgbAliceBlue"
  'MsgBox Src.Range("B" & LTrim(str(RowNm + 1))).Value 'This displays "rgbAliceBlue"
  NowXlClr = Src.Range("B" & LTrim(str(RowNm + 1))).Value
  Selection.Offset(LTrim(str(RowNm)), 2).Interior.Color = XlRgbColor.rgbAliceBlue 'This is Okay
  Selection.Offset(LTrim(str(RowNm)), 2).Interior.Color = XlRgbColor.NowXlClr 'This line fails
  '.[rgb{color_name}]
  RowNm = RowNm + 1
 Loop
End Sub
The following code works fine.
Code:
Selection.Offset(LTrim(str(RowNm)), 2).Interior.Color = XlRgbColor.rgbAliceBlue
but the following code 'NowXlClr' is highlighted and the error message displayed is 'Method or data member not found'.
Code:
  Selection.Offset(LTrim(str(RowNm)), 2).Interior.Color = XlRgbColor.NowXlClr
What is the mistake I am doing?
Should I use ' '.[rgb{color_name}]' which is mentioned in this page by @Rhodie72
user-offline.png

If so, how to use it?
Or how to edit my code?
Thanks for the response in advance.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,416
Messages
6,124,774
Members
449,187
Latest member
hermansoa

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top