'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
It would have been awesome if I can get RGB colour name.
Yes! And what's more, you can name it yourself, too. Here's how: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
[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
[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
[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
?RGB(232, 241, 209)
ActiveCell.Interior.Color = XlRgbColor.[rgb{color_name}] ' Press ctrl+space to activatre the intellisense feature of VBA
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
Selection.Offset(LTrim(str(RowNm)), 2).Interior.Color = XlRgbColor.rgbAliceBlue
Selection.Offset(LTrim(str(RowNm)), 2).Interior.Color = XlRgbColor.NowXlClr